Skip to content

topmark.toml.pyproject

topmark / toml / pyproject

Helpers for extracting TopMark TOML content from pyproject.toml.

This module contains small, schema-aware helpers for locating TopMark's [tool.topmark] table inside a parsed pyproject.toml document.

extract_pyproject_topmark_table

extract_pyproject_topmark_table(data)

Return the [tool.topmark] table from a parsed pyproject.toml mapping.

Parameters:

Name Type Description Default
data TomlTable

Parsed TOML document mapping.

required

Returns:

Type Description
TomlTable | None

The nested [tool.topmark] table if present and well-formed;

TomlTable | None

otherwise None.

Source code in src/topmark/toml/pyproject.py
def extract_pyproject_topmark_table(data: TomlTable) -> TomlTable | None:
    """Return the `[tool.topmark]` table from a parsed `pyproject.toml` mapping.

    Args:
        data: Parsed TOML document mapping.

    Returns:
        The nested `[tool.topmark]` table if present and well-formed;
        otherwise `None`.
    """
    tool_section: TomlValue | None = data.get("tool")
    if not isinstance(tool_section, dict):
        return None

    topmark_section: TomlValue | None = tool_section.get("topmark")
    if not isinstance(topmark_section, dict):
        return None

    return topmark_section