Skip to content

Conversation

@chrisjsewell
Copy link
Member

@chrisjsewell chrisjsewell commented Jun 24, 2024

Purpose

A common use-case is that users simply want to point Sphinx towards a Python module, and have it generate documentation automatically.

This is not possible currently, without a "pre-build" step of running the sphinx-autogen CLI.

This PR adds sphinx.ext.apidoc as a sphinx extension, to incorporate the source file generation into the sphinx build.

References

@chrisjsewell chrisjsewell marked this pull request as draft June 24, 2024 12:41
@chrisjsewell chrisjsewell requested a review from picnixz June 24, 2024 12:42
@chrisjsewell
Copy link
Member Author

@picnixz note this is still a draft, but perhaps you would like to provide some initial feedback

A common usecase,
is that users simply want to point sphinx towards a Python module,
and have it generate documentation automatically.

This is not possible currently,
without a "pre-build" step of running the `sphinx-autogen` CLI.

This PR adds `sphinx.ext.apidoc` as a sphinx extension,
to incorporate the source file generation into the sphinx build.
@AA-Turner AA-Turner changed the title ✨ Add sphinx.ext.apidoc extension Allow using sphinx.ext.apidoc as an extension Jul 3, 2024
Copy link
Member

@AA-Turner AA-Turner left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very brief skim:

@@ -0,0 +1,10 @@
"""So program can be started with ``python -m sphinx.apidoc ...``"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
"""So program can be started with ``python -m sphinx.apidoc ...``"""
"""Command-line interface for the apidoc extension."""

from sphinx.locale import __
from sphinx.util.console import bold

from . import WARNING_TYPE, _remove_old_files, create_modules_toc_file, logger, recurse_tree
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid relative imports:

Suggested change
from . import WARNING_TYPE, _remove_old_files, create_modules_toc_file, logger, recurse_tree
from sphinx.ext.apidoc import WARNING_TYPE, _remove_old_files, create_modules_toc_file, logger, recurse_tree

Comment on lines 638 to +639
def main(argv: Sequence[str] = (), /) -> int:
"""Parse and check the command line arguments."""
"""Run the apidoc CLI."""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps move main() into __main__.py?


# destination path should be relative to the source directory
# TODO account for Windows path?
if not (destination := _check_string(i, options, 'destination', True)):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lone Booleans at call sites are often hard to interpret -- perhaps make required a keyword-only argument?

return options[key]


@dataclass
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps?:

Suggested change
@dataclass
@dataclass(frozen=True)

I'd also maybe set slots=True, but that is only Python 3.10+

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to our release plan, we should have dropped 3.9 some months ago so maybe we could first move to 8.x by dropping 3.9 (there are quite a lot of annoying things in between 3.9 and 3.10).

@AA-Turner
Copy link
Member

Closing in favour of #13220, which doesn't have merge conflicts. But feel free to close that one and reopen this one if you'd prefer.

@AA-Turner AA-Turner closed this Jan 7, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 5, 2025
@sphinx-doc sphinx-doc unlocked this conversation Feb 12, 2025
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 13, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants