protokolo.config module¶
The global configuration of Protokolo.
- protokolo.config.parse_toml(toml: str | IO[bytes], section: Sequence[str] | None = None) dict[str, Any][source]¶
Parse a string representing a TOML file, and return a dictionary representing the defined section.
- Parameters:
toml – A TOML string or binary file object.
sections – A list of nested sections, for example
["protokolo", "section"]to return the values of[protokolo.section]
- Raises:
TypeError – toml is not a valid type.
tomllib.TOMLDecodeError – not valid TOML.
- class protokolo.config.TOMLConfig(values: dict[str, str | int | float | bool | datetime | date | None | Mapping[str, TOMLValue] | list[TOMLType]] = NOTHING, source=None)[source]¶
Bases:
objectA utility class to hold data parsed from a TOML file.
Immediately after object instantiation,
validate()is called.- classmethod from_dict(values: dict[str, Any], source: str | PathLike | None = None) Self[source]¶
Generate
TOMLConfigfrom a dictionary containing the keys and values. This is useless for theTOMLConfigbase class, but potentially useful for subclasses that change the__init__signature.- Raises:
DictTypeError – value isn’t an expected/supported type.
DictTypeListError – if a list contains elements other than a dict.
- as_dict() dict[str, str | int | float | bool | datetime | date | None | Mapping[str, TOMLValue] | list[TOMLType]][source]¶
Return a mapping of the
TOMLConfig.
- validate() None[source]¶
Verify that all keys contain valid TOML types. This is automatically run on object instantiation.
- Raises:
DictTypeError – value isn’t an expected/supported type.
DictTypeListError – if a list contains elements that aren’t supported.
- class protokolo.config.SectionAttributes(values: dict[str, str | int | float | bool | datetime | date | None | Mapping[str, TOMLValue] | list[TOMLType]] = NOTHING, source=None, title: str = 'TODO: No section title defined', level: int = 1, order: int | None = None)[source]¶
Bases:
TOMLConfigA data container to hold some metadata for a
compile.Sectionobject.- classmethod from_dict(values: dict[str, Any], source: str | PathLike | None = None) Self[source]¶
Generate
SectionAttributesfrom a dictionary containing the keys and values.- Raises:
AttributeNotPositiveError – one of the values should have been positive.
DictTypeError – value isn’t an expected/supported type.
DictTypeListError – if a list contains elements other than a dict.
- validate() None[source]¶
- Raises:
AttributeNotPositiveError – one of the values should have been positive.
DictTypeError – value isn’t an expected/supported type.
DictTypeListError – if a list contains elements other than a dict.
- class protokolo.config.GlobalConfig(values: dict[str, str | int | float | bool | datetime | date | None | Mapping[str, TOMLValue] | list[TOMLType]] = NOTHING, source=None, changelog: str | None = None, markup: str | None = None, directory: str | None = None)[source]¶
Bases:
TOMLConfigA container object for config values of the global
.protokolo.tomlfile.- classmethod from_file(path: str | PathLike) Self[source]¶
Factory method to create a
GlobalConfigfrom a path. The exact table that is loaded from the file depends on the file name. Inpyproject.toml, the table[tool.protokolo]is loaded, whereas[protokolo]is loaded everywhere else.- Raises:
OSError – if the file could not be opened.
tomllib.TOMLDecodeError – if the file could not be decoded.
DictTypeError – value isn’t an expected/supported type.
DictTypeListError – if a list contains elements other than a dict.