protokolo.compile module¶
Code to combine the files in changelog.d/ into a single text block.
- class protokolo.compile.Fragment(text: str, source=None)[source]¶
Bases:
objectA fragment, analogous to a file.
- class protokolo.compile.Section(attrs: SectionAttributes = NOTHING, markup: Literal['markdown', 'restructuredtext'] = 'markdown', source=None)[source]¶
Bases:
objectA section, analogous to a directory.
- attrs: SectionAttributes¶
- classmethod from_directory(directory: str | PathLike, level: int = 1, markup: Literal['markdown', 'restructuredtext'] = 'markdown', section_format_pairs: dict[str, str] | None = None) Self[source]¶
Factory method to recursively create a
Sectionfrom a directory.- Parameters:
directory – The changelog.d directory.
level – The level of the root
Section. This is overridden by the level value in.protokolo.toml, if any.markup – The markup language.
section_format_pairs – Additional key-value pairs used to format the section headings, applied recursively to all subsections.
- Raises:
OSError – input/output error.
ProtokoloTOMLNotFoundError –
.protokolo.tomldoesn’t exist.ProtokoloTOMLIsADirectoryError –
.protokolo.tomlis not a file.tomllib.TOMLDecodeError –
.protokolo.tomlcouldn’t be parsed.DictTypeError –
.protokolo.tomlfields have the wrong type.AttributeNotPositiveError – value in
.protokolo.tomlshould be a positive integer.
- compile() str[source]¶
Compile the entire section recursively, first printing the fragments in order, then the subsections.
Empty sections are not compiled.
- Raises:
HeadingFormatError – could not format heading of section.
- write_to_buffer(buffer: StringIO | None = None) StringIO[source]¶
Like compile, but writing to a
StringIObuffer.- Raises:
HeadingFormatError – could not format heading of section.
- is_empty() bool[source]¶
A
Sectionis empty if it contains neither fragments nor subsections. If it contains no fragments, and its subsections are empty, then it is also considered empty.