Skip to content

scripts.gen_api_reference

Synchronize the exhaustive static API reference with the Python source tree.

View the complete module source at #L1-L103.

API details

Each callable below includes its exact signature, type annotations, inputs, defaults, return contract, documented exceptions, implementation source, and parsed docstring sections when the source provides them.

scripts.gen_api_reference

Synchronize the exhaustive static API reference with the Python source tree.

scripts.gen_api_reference.GENERATED_HEADER module-attribute

GENERATED_HEADER = '<!-- Generated by scripts/gen_api_reference.py. Do not edit directly. -->\n\n'

scripts.gen_api_reference.expected_pages

expected_pages() -> dict[Path, str]

Return every generated reference path and its expected contents.

Source code in scripts/gen_api_reference.py
def expected_pages() -> dict[Path, str]:
    """Return every generated reference path and its expected contents."""

    runtime_inventory = build_inventory()
    pages = {
        REPOSITORY_ROOT / "docs" / module.page_path: GENERATED_HEADER
        + render_module_page(module)
        for module in build_repository_inventory()
    }
    pages[REPOSITORY_ROOT / "docs" / "reference" / "cli-options.md"] = (
        GENERATED_HEADER + render_cli_reference(build_cli_inventory())
    )
    pages[REPOSITORY_ROOT / "docs" / "reference" / "python-symbols.md"] = (
        GENERATED_HEADER + render_symbol_index(runtime_inventory)
    )
    return pages

scripts.gen_api_reference.generated_pages_on_disk

generated_pages_on_disk() -> set[Path]

Return generated reference pages currently present in the docs tree.

Source code in scripts/gen_api_reference.py
def generated_pages_on_disk() -> set[Path]:
    """Return generated reference pages currently present in the docs tree."""

    docs_dir = REPOSITORY_ROOT / "docs"
    return {
        path
        for path in docs_dir.rglob("*.md")
        if path.read_text(encoding="utf-8").startswith(GENERATED_HEADER)
    }

scripts.gen_api_reference.check

check() -> int

Report missing, stale, or unexpected generated pages.

Source code in scripts/gen_api_reference.py
def check() -> int:
    """Report missing, stale, or unexpected generated pages."""

    expected = expected_pages()
    current = generated_pages_on_disk()
    issues: list[str] = []
    for path, content in expected.items():
        if not path.exists():
            issues.append(
                f"Missing generated page: {path.relative_to(REPOSITORY_ROOT)}"
            )
        elif path.read_text(encoding="utf-8") != content:
            issues.append(f"Stale generated page: {path.relative_to(REPOSITORY_ROOT)}")
    for path in sorted(current - expected.keys()):
        issues.append(f"Unexpected generated page: {path.relative_to(REPOSITORY_ROOT)}")

    if issues:
        for issue in issues:
            print(issue)
        return 1
    print(f"Generated reference is current: {len(expected)} pages")
    return 0

scripts.gen_api_reference.write

write() -> int

Write every reference page and remove obsolete generated pages.

Source code in scripts/gen_api_reference.py
def write() -> int:
    """Write every reference page and remove obsolete generated pages."""

    expected = expected_pages()
    for path in generated_pages_on_disk() - expected.keys():
        path.unlink()
    for path, content in expected.items():
        path.parent.mkdir(parents=True, exist_ok=True)
        path.write_text(content, encoding="utf-8")
    print(f"Synchronized {len(expected)} generated reference pages")
    return 0

scripts.gen_api_reference.main

main() -> int

Parse the synchronization mode and update or verify generated pages.

Source code in scripts/gen_api_reference.py
def main() -> int:
    """Parse the synchronization mode and update or verify generated pages."""

    parser = argparse.ArgumentParser(description=__doc__)
    parser.add_argument(
        "--check",
        action="store_true",
        help="fail instead of writing when generated references are stale",
    )
    args = parser.parse_args()
    return check() if args.check else write()

Complete contract reference

Expand any definition for its exact inputs, annotations, defaults, return contract, directly raised exceptions, source-grounded behavior, and immutable line link. This section includes private and nested definitions that ordinary API generators omit.

scripts.gen_api_reference.expected_pages · function
scripts.gen_api_reference.expected_pages() -> dict[Path, str]

Return every generated reference path and its expected contents.

Parameters

This callable has no explicit inputs.

Returns

  • Type: dict[Path, str]
  • Direct return expressions: pages

Exceptions and behavior

Function expected_pages calls build_inventory, render_module_page, build_repository_inventory, render_cli_reference; returns pages. No direct raise statement appears in this definition.

View source #L23-L38.

scripts.gen_api_reference.generated_pages_on_disk · function
scripts.gen_api_reference.generated_pages_on_disk() -> set[Path]

Return generated reference pages currently present in the docs tree.

Parameters

This callable has no explicit inputs.

Returns

  • Type: set[Path]
  • Direct return expressions: {path for path in docs_dir.rglob('*.md') if path.read_text(encoding='utf-8').startswith(GENERATED_HEADER)}

Exceptions and behavior

Function generated_pages_on_disk calls docs_dir.rglob, path.read_text(encoding='utf-8').startswith, path.read_text; returns {path for path in docs_dir.rglob('*.md') if path.read_text(encoding='utf-8').startswith(GENERATED_HEADER)}. No direct raise statement appears in this definition.

View source #L41-L49.

scripts.gen_api_reference.check · function
scripts.gen_api_reference.check() -> int

Report missing, stale, or unexpected generated pages.

Parameters

This callable has no explicit inputs.

Returns

  • Type: int
  • Direct return expressions: 1; 0

Exceptions and behavior

Function check calls expected_pages, generated_pages_on_disk, expected.items, path.exists; has 2 explicit return paths. No direct raise statement appears in this definition.

View source #L52-L73.

scripts.gen_api_reference.write · function
scripts.gen_api_reference.write() -> int

Write every reference page and remove obsolete generated pages.

Parameters

This callable has no explicit inputs.

Returns

  • Type: int
  • Direct return expressions: 0

Exceptions and behavior

Function write calls expected_pages, generated_pages_on_disk, expected.keys, path.unlink; returns 0. No direct raise statement appears in this definition.

View source #L76-L86.

scripts.gen_api_reference.main · function
scripts.gen_api_reference.main() -> int

Parse the synchronization mode and update or verify generated pages.

Parameters

This callable has no explicit inputs.

Returns

  • Type: int
  • Direct return expressions: check() if args.check else write()

Exceptions and behavior

Function main calls argparse.ArgumentParser, parser.add_argument, parser.parse_args, check; returns check() if args.check else write(). No direct raise statement appears in this definition.

View source #L89-L99.

Complete symbol map

This map also includes private definitions and nested helpers. The signature column exposes every explicit input even when an internal helper has no dedicated parameter prose.

Symbol Kind Signature and inputs What it does Source
expected_pages function expected_pages() -> dict[Path, str] Return every generated reference path and its expected contents. #L23-L38
generated_pages_on_disk function generated_pages_on_disk() -> set[Path] Return generated reference pages currently present in the docs tree. #L41-L49
check function check() -> int Report missing, stale, or unexpected generated pages. #L52-L73
write function write() -> int Write every reference page and remove obsolete generated pages. #L76-L86
main function main() -> int Parse the synchronization mode and update or verify generated pages. #L89-L99