Skip to content
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

Add sphinx.ext.apidoc extension #13220

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

AA-Turner
Copy link
Member

@AA-Turner AA-Turner commented Jan 7, 2025

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.

Per the original PR, there is no documentation and two outstanding TODO comments in the PR.

References

cc @chrisjsewell

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.

Co-authored-by: Chris Sewell <[email protected]>
@timhoffm
Copy link
Contributor

timhoffm commented Jan 7, 2025

Could this get at least a minimal doc page under https://github.com/sphinx-doc/sphinx/tree/master/doc/usage/extensions?

@AA-Turner
Copy link
Member Author

https://sphinx--13220.org.readthedocs.build/en/13220/usage/extensions/apidoc.html

Comment on lines +55 to +58
{'destination': 'source/', 'path': 'path/to/module'},
{
'destination': 'source/',
'path': 'path/to/another_module',
Copy link
Contributor

@timhoffm timhoffm Jan 8, 2025

Choose a reason for hiding this comment

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

Minor: I would put 'path' first. The module to be documented is the main aspect.

Suggested change
{'destination': 'source/', 'path': 'path/to/module'},
{
'destination': 'source/',
'path': 'path/to/another_module',
{'path': 'path/to/module', 'destination': 'source/'},
{
'path': 'path/to/another_module',
'destination': 'source/',

Alternatively, the modules are so prominent that one could make them keys of a dict:

apidoc_modules = {
    'path/to/module': {'destination': 'source/'},
    'path/to/other_module': {
        'destination': 'source/',
        'exclude_patterns': ['**/test*'],
        'maxdepth': 4,
        'followlinks': False,
        'separatemodules': False,
        'includeprivate': False,
        'noheadings': False,
        'modulefirst': False,
        'implicit_namespaces': False,
    },
}

:type: :code-py:`Sequence[dict[str, Any]]`
:default: :code-py:`()`

A list or sequence of dictionaries describing modules to document.
Copy link
Contributor

Choose a reason for hiding this comment

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

On a side note, I could see the case for making config parameters applying to all modules. This would remove the need for repeating a lot of keys for multiple modules.

apidoc_module_config = {
        'followlinks': False,
        'separatemodules': False,
        'includeprivate': False,
        'noheadings': False,
}
apidoc_modules = {
        {'path': 'path/to/module'},
        {'path': 'path/to/other_module'},
        {'path': 'path/to/third_module', 'includeprivate': True}, # overriding global settings
}

Implementation-wise one would just merge the dicts apidoc_module_config and the individual config dicts.

But that could also be added later.

Copy link
Member Author

Choose a reason for hiding this comment

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

Cc @chrisjsewell -- I just rebased the original PR so would prefer to have your input on larger design changes such as Tim suggests.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks @AA-Turner I'll have a look in the next few days

# Conflicts:
#	sphinx/ext/apidoc/_shared.py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
extensions:apidoc type:enhancement enhance or introduce a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants