sphinx-autostub
This package generates a Sphinx API reference using only PEP 561 type stubs
(*.pyi files).
This may be of appeal to projects satisfying one or both of the following points:
- Significant effort was invested into making high-quality type stubs.
- It's tricky to load the extension on services like Read the Docs and use Sphinx' autodoc feature for generation. Causes could be that the package requires a GPU or is simply too costly to compile in the cloud.
This generator only needs stubs. It parses them with Python's builtin ast
module, accepts Google or NumPy style docstrings, and converts them to
reStructuredText via Sphinx's napoleon parser. It was developed for the
docstring-rich stubs that nanobind's
stubgen produces, but the format is generic: pybind11-stubgen output and
hand-written stubs work as well. The generated pages use the :no-index:
option and therefore require Sphinx 7.2 or newer.
Usage
The easiest way to use this package is as a Sphinx extension. For this, declare
the following in conf.py:
extensions = ['sphinx_autostub']
autostub_packages = ['mypkg']
This renders the installed stubs of mypkg to <srcdir>/api/mypkg/, using one
page per module, plus an index.rst to place in a toctree. Documented
parameters that the stubs do not accept are reported as build warnings. Further
settings adjust the rendering:
autostub_exclude = [r'_.*', 'detail'] # full-match regexes over unqualified names
autostub_style = 'numpy' # 'google' (default), 'numpy', or 'rst'
autostub_sections = { # split the top-level module thematically
'Widgets': ['Button', 'Label', r'Checkbox\w*'],
'Application': [r'load_\w+', r'gui_\w+'],
}
A sections table groups the top-level module's contents into one page per entry, in table order. Each name joins the first section with a matching regex, leftovers land on an 'Other' page, and the submodules keep one page each. A pattern that matches nothing, and a name that several sections claim, are reported as build warnings.
The page-per-module layout is also available from the command line:
sphinx-autostub mypkg docs/api
sphinx-autostub path/to/stubs docs/api --style numpy
Advanced usage
The package can also be used as a library to implement filtering and layout policies beyond what the plain-data settings above can express. This mode and the underlying interface are documented in docs/advanced.rst.
License
BSD 3-clause. See the LICENSE file.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sphinx_autostub-0.2.0.tar.gz.
File metadata
- Download URL: sphinx_autostub-0.2.0.tar.gz
- Upload date:
- Size: 18.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
69dfbe912b220192b090981d15f5e99c6287e67340c6f174c70716c5a5026693
|
|
| MD5 |
17e52a0ebc960ae2db965258bec78178
|
|
| BLAKE2b-256 |
c661d3caab0424602504ef1c3167920d8772a2d1d6c7ef2563e62376ce9452b3
|
File details
Details for the file sphinx_autostub-0.2.0-py3-none-any.whl.
File metadata
- Download URL: sphinx_autostub-0.2.0-py3-none-any.whl
- Upload date:
- Size: 12.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/6.2.0 CPython/3.13.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8c065c7d6dc851eb5c66555c7d0d829df65cd2d7c77dd8e0fc11ad3fba89f392
|
|
| MD5 |
8392721ec8fbd9b962549c9acfbcf24e
|
|
| BLAKE2b-256 |
f82a6bf4b16c46b49029e514927d90c87c296f6152c83188ebc57003109698a1
|