docgen module

Generate a markdown reference of every class that can be configured through yaml.

Run from the repository root to (re)generate the reference:

python -m ssb_dash_framework.config.docgen
python -m ssb_dash_framework.config.docgen --check  # exit 1 if outdated

The script only uses absolute imports, so it can be moved anywhere in the repository.

collect_classes()

Find all concrete classes that can be created through a from_yaml method.

Return type:

list[type]

Returns:

The classes, sorted by module and name.

default_output_path()

Path to the generated markdown file.

Return type:

Path

Returns:

The absolute path of the markdown file.

describe_parameters(cls)

Describe the arguments that can be set in yaml for a class.

Parameters:

cls (type) – The class to describe.

Return type:

tuple[list[tuple[str, str, str, str]], bool]

Returns:

Rows of (name, type, default, description), and whether extra keyword arguments are accepted.

find_repo_root()

Find the repository root by searching upwards for pyproject.toml.

Return type:

Path

Returns:

The repository root, or the current working directory if none is found.

first_paragraph(docstring)

Return the first paragraph of a docstring as a single line.

Parameters:

docstring (str | None) – The cleaned docstring.

Return type:

str

Returns:

The first paragraph, or an empty string.

format_annotation(annotation)

Format a type annotation as short readable text.

Parameters:

annotation (Any) – The annotation to format.

Return type:

str

Returns:

The annotation without module prefixes, or an empty string if missing.

format_default(value)

Format a default value for the documentation.

Parameters:

value (Any) – The default value.

Return type:

str

Returns:

The repr of the value, or the type name if the repr is not stable.

from_yaml_owner(cls)

Return the class defining a custom from_yaml, or None if the default is used.

Parameters:

cls (type) – The class to inspect.

Return type:

type | None

Returns:

The class in the MRO that defines from_yaml, unless it is YamlLoadable.

import_all_modules()

Import all submodules so every YamlLoadable subclass registers itself.

Return type:

None

main(argv=None)

Write the reference, or check that it is up to date.

Parameters:

argv (list[str] | None) – Command line arguments.

Return type:

int

Returns:

The exit code.

parse_args_section(docstring)

Extract argument descriptions from a Google style docstring.

Parameters:

docstring (str | None) – The cleaned docstring.

Return type:

dict[str, str]

Returns:

Mapping from argument name to its description.

render()

Render the full markdown reference.

Return type:

str

Returns:

The markdown content.

render_class(cls)

Render the markdown section for a single class.

Parameters:

cls (type) – The class to document.

Return type:

str

Returns:

The markdown section.