-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Allow using sphinx.ext.apidoc
as an extension
#12471
base: master
Are you sure you want to change the base?
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
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).
A common use case,
is that users want to simply point sphinx towards a Python module, and have it generate documentation automatically.
(see e.g. readthedocs/readthedocs.org#1139)
This is not possible currently,
without a "pre-build" step of running the
sphinx-apidoc
CLI.(and in fact there are numerous examples of users calling
sphinx-apidoc
within theirconf.py
to work around this)This PR adds
sphinx.ext.apidoc
as a sphinx extension, to incorporate the source file generation into the sphinx build in a "formal" manner, using the API rather than the CLI.related to #6829 (but does not close it)
This PR is currently in draft, since there are a number of TODOs in the code, and documentation needs to be added.