Sphinx extension to automatically generate autosummary tables for Python packages
Project description
sphinx-autopackagesummary
This is a Sphinx extension that makes it possible to automatically generate API documentation for deeply nested Python packages using the built-in autosummary extension.
The problem with the built-in autosummary directive is that it does not automatically pick up nested sub-modules, requiring tedious manual work to specify the entire module tree.
Instead of this:
.. autosummary::
:toctree: _autosummary
mypackage.submodule1
mypackage.submodule2
mypackage.submodule3
You can now simply use this:
.. autopackagesummary:: mypackage
:toctree: _autosummary
Usage
To make use of this extension, the following steps are needed:
- Install the module using pip.
pip install sphinx-autopackagesummary
- Enable it in
conf.py
.
extensions = ['sphinx.ext.autosummary', 'sphinx_autopackagesummary']
autosummary_generate = True
- Make use of the new syntax
Configuration
The autopackagesummary
directive accepts all options that are supported by
autosummary
, which are simply passed on.
To exclude packages from being imported, add them to the config setting
autosummary_mock_imports
.
Recursive generation
If your packages have subpackages, it is possible to use this recursively by customizing the autosummary template. For example, you could have your root package documented like so:
.. py:package:: mypackage
This is my package.
.. autopackagesummary:: mypackage
:toctree: _autosummary
:template: autosummary/package.rst
And then create a _templates/autosummary/package.rst
like so:
{{ fullname | escape | underline }}
.. automodule:: {{ fullname }}
.. autopackagesummary:: {{ fullname }}
:toctree: .
:template: autosummary/package.rst
Alternatively, you can override the default module.rst
template.
Note the use of .
for the toctree setting: otherwise, the _autosummary
directories would keep nesting, like _autosummary/_autosummary/module.rst
.
License
This extension has been placed into the public domain. If you make a contribution to this repository, you are placing your modifications into the public domain as well.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
File details
Details for the file sphinx_autopackagesummary-1.3-py3-none-any.whl
.
File metadata
- Download URL: sphinx_autopackagesummary-1.3-py3-none-any.whl
- Upload date:
- Size: 3.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.46.0 CPython/3.8.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | cfa1462d1301afecd0724bbe42b26de811c2717d000e9fbe1b73e16932fddb8c |
|
MD5 | 62d7ac66f04bad011b6971b510bb2973 |
|
BLAKE2b-256 | 12b98597c79390de7f7e99c46b89a1344b1bc8a3d09d002621ec29793c35d5b3 |