-
-
Notifications
You must be signed in to change notification settings - Fork 2.4k
Allow using sphinx.ext.apidoc as an extension
#12471
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
@picnixz note this is still a draft, but perhaps you would like to provide some initial feedback |
f27dd11 to
dd9615a
Compare
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.
dd9615a to
30ce9b3
Compare
sphinx.ext.apidoc extensionsphinx.ext.apidoc as an extension
AA-Turner
left a comment
There was a problem hiding this 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 ...``""" | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| """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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid relative imports:
| 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 |
| def main(argv: Sequence[str] = (), /) -> int: | ||
| """Parse and check the command line arguments.""" | ||
| """Run the apidoc CLI.""" |
There was a problem hiding this comment.
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)): |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Perhaps?:
| @dataclass | |
| @dataclass(frozen=True) |
I'd also maybe set slots=True, but that is only Python 3.10+
There was a problem hiding this comment.
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).
|
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. |
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-autogenCLI.This PR adds
sphinx.ext.apidocas a sphinx extension, to incorporate the source file generation into the sphinx build.References