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: object

A fragment, analogous to a file.

text: str
source: PurePath | None
compile() str[source]

Compile the fragment. For the time being, this just means adding a newline at the end if one does not exist.

class protokolo.compile.Section(attrs: SectionAttributes = NOTHING, markup: Literal['markdown', 'restructuredtext'] = 'markdown', source=None)[source]

Bases: object

A section, analogous to a directory.

attrs: SectionAttributes
markup: Literal['markdown', 'restructuredtext']
source: PurePath | None
fragments: set[Fragment]
subsections: set[Self]
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 Section from 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:
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 StringIO buffer.

Raises:

HeadingFormatError – could not format heading of section.

is_empty() bool[source]

A Section is empty if it contains neither fragments nor subsections. If it contains no fragments, and its subsections are empty, then it is also considered empty.

sorted_fragments() Iterator[Fragment][source]

Yield the fragments, ordered by their source. Fragments that do not have a source are sorted afterwards by their text.

sorted_subsections() Iterator[Self][source]

Yield the subsections, first ordered by their order value, then the remainder sorted alphabetically.