API Reference

This page documents the Python API for sphinx-autodoc-toml.

Parser Module

Core parser for extracting doc-comments from TOML files.

Specification: The parser MUST recognize doc-comments marked with #: syntax. S_PARSER_001
status: implemented
tags: parser, syntax
links outgoing: R_SPEC_001
links incoming: R_SPEC_001
Specification: The parser MUST validate the Separator Rule for doc-comments. S_PARSER_002
status: implemented
tags: parser, validation
links outgoing: R_SPEC_002, R_PARSE_003
links incoming: R_SPEC_002, R_PARSE_003
Specification: The parser MUST validate the Attachment Rule for doc-comments. S_PARSER_003
status: implemented
tags: parser, validation
links outgoing: R_SPEC_003, R_PARSE_004
links incoming: R_SPEC_003, R_PARSE_004
Specification: The parser MUST support multi-line doc-comments. S_PARSER_004
status: implemented
tags: parser, syntax
links outgoing: R_SPEC_004
links incoming: R_SPEC_004
Specification: The parser MUST use tomlkit to preserve comments and whitespace. S_PARSER_005
status: implemented
tags: parser, toml
links outgoing: R_PARSE_001
links incoming: R_PARSE_001
Specification: The parser MUST extract all valid doc-comments from a TOML file. S_PARSER_006
status: implemented
tags: parser, extraction
links outgoing: R_PARSE_002
links incoming: R_PARSE_002
Specification: The parser MUST identify and parse TOML table headers. S_PARSER_007
status: implemented
tags: parser, toml
links outgoing: R_PARSE_005
links incoming: R_PARSE_005
Specification: The parser MUST identify and parse TOML key-value pairs. S_PARSER_008
status: implemented
tags: parser, toml
links outgoing: R_PARSE_005
links incoming: R_PARSE_005
Specification: The parser MUST determine hierarchical TOML paths for items. S_PARSER_009
status: implemented
tags: parser, toml, hierarchy
links outgoing: R_PARSE_006
links incoming: R_PARSE_006
Specification: The parser MUST extract TOML content for documented items. S_PARSER_010
status: implemented
tags: parser, extraction
links outgoing: R_PARSE_007
links incoming: R_PARSE_007
class sphinx_autodoc_toml.parser.DocComment(path: List[str], content: str, line_number: int, toml_content: str = '')[source]

Bases: object

Represents a doc-comment block extracted from a TOML file.

property full_path: str

Return the full dotted path (e.g., ‘project.dependencies’).

property toml_path: str

Return the TOML table notation (e.g., ‘[project.dependencies]’).

class sphinx_autodoc_toml.parser.TomlDocParser(toml_path: Path)[source]

Bases: object

Parser for extracting doc-comments from TOML files according to TOML-Doc spec.

DOC_COMMENT_PATTERN = re.compile('^#:\\s?(.*)')
KEY_PATTERN = re.compile('^([a-zA-Z0-9_-]+)\\s*=')
TABLE_PATTERN = re.compile('^\\[([^\\]]+)\\]')
parse() List[DocComment][source]

Parse the TOML file and extract all valid doc-comments.

Returns:

List of DocComment objects

sphinx_autodoc_toml.parser.parse_toml_file(toml_path: Path) List[DocComment][source]

Parse a TOML file and extract all doc-comments.

Parameters:

toml_path – Path to the TOML file

Returns:

List of DocComment objects

Example

>>> from pathlib import Path
>>> doc_comments = parse_toml_file(Path("pyproject.toml"))
>>> for dc in doc_comments:
...     print(f"{dc.toml_path}: {dc.content}")

Extension Module

Sphinx extension for autodoc-toml directive.

Specification: The extension MUST provide an autodoc-toml directive for Sphinx. S_EXT_001
status: implemented
tags: sphinx, directive
links outgoing: R_SPHINX_001
links incoming: R_SPHINX_001
Specification: The autodoc-toml directive MUST accept a file path argument. S_EXT_002
status: implemented
tags: sphinx, directive
links outgoing: R_SPHINX_002
links incoming: R_SPHINX_002
Specification: The extension MUST resolve both relative and absolute file paths. S_EXT_003
status: implemented
tags: sphinx, paths
links outgoing: R_SPHINX_003
links incoming: R_SPHINX_003
Specification: The extension MUST generate proper docutils nodes from doc-comments. S_EXT_004
status: implemented
tags: sphinx, generation
links outgoing: R_SPHINX_004
links incoming: R_SPHINX_004
Specification: The extension MUST use nested_parse to support embedded Sphinx directives. S_EXT_005
status: implemented
tags: sphinx, directives
links outgoing: R_SPHINX_005
links incoming: R_SPHINX_005
Specification: The extension MUST log clear warnings and errors for invalid files. S_EXT_006
status: implemented
tags: sphinx, error-handling
links outgoing: R_SPHINX_006
links incoming: R_SPHINX_006
Specification: The extension MUST display TOML content in collapsible admonitions. S_EXT_007
status: implemented
tags: sphinx, ui
links outgoing: R_SPHINX_007
links incoming: R_SPHINX_007
class sphinx_autodoc_toml.extension.AutodocTomlDirective(name, arguments, options, content, lineno, content_offset, block_text, state, state_machine)[source]

Bases: Directive

Directive to automatically document TOML files with embedded doc-comments.

Usage:
final_argument_whitespace = True

May the final argument contain whitespace?

has_content = False

May the directive have content?

option_spec = {'recursive': <function flag>, 'show-all': <function flag>}

Mapping of option names to validator functions.

optional_arguments = 0

Number of optional arguments after the required arguments.

required_arguments = 1

Number of required directive arguments.

run() List[Node][source]

Execute the directive.

Returns:

List of docutils nodes to insert into the document

sphinx_autodoc_toml.extension.setup(app: Sphinx) Dict[str, Any][source]

Sphinx extension setup function.

Parameters:

app – The Sphinx application instance

Returns:

Extension metadata

Linter Module

Linter and formatter for TOML-Doc specification compliance.

Specification: The linter tool MUST validate TOML-Doc specification compliance. S_LINT_001
status: planned
tags: linter, validation
links outgoing: R_LINT_001
links incoming: R_LINT_001
Specification: The linter MUST check for Separator Rule violations. S_LINT_003
status: planned
tags: linter, validation
links outgoing: R_LINT_002
links incoming: R_LINT_002
Specification: The linter MUST check for Attachment Rule violations. S_LINT_004
status: planned
tags: linter, validation
links outgoing: R_LINT_003
links incoming: R_LINT_003
Specification: The linter MUST provide auto-formatting to fix spec violations. S_LINT_005
status: planned
tags: linter, formatting
links outgoing: R_LINT_004
links incoming: R_LINT_004
class sphinx_autodoc_toml.linter.LintError(line: int, message: str, severity: str = 'error')[source]

Bases: object

Represents a linting error in a TOML file.

class sphinx_autodoc_toml.linter.TomlDocLinter(toml_path: Path)[source]

Bases: object

Linter for TOML-Doc specification compliance.

format() str[source]

Format the TOML file to comply with TOML-Doc specification.

Returns:

Formatted TOML content

lint() List[LintError][source]

Lint the TOML file for TOML-Doc specification compliance.

Returns:

List of LintError objects

sphinx_autodoc_toml.linter.main() int[source]

Main entry point for the toml-doc-lint CLI tool.