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.
Metadata
Release files for sphinx-autostub 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sphinx_autostub-0.2.0.tar.gz | 18.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sphinx_autostub-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 31.0 kB
Release files / sphinx_autostub-0.2.0.tar.gz
| Download URL | sphinx_autostub-0.2.0.tar.gz |
|---|---|
| Size | 18.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69dfbe912b220192b090981d15f5e99c6287e67340c6f174c70716c5a5026693
|
|
BLAKE2b-256 checksum How to use checksums |
c661d3caab0424602504ef1c3167920d8772a2d1d6c7ef2563e62376ce9452b3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|
Release files / sphinx_autostub-0.2.0-py3-none-any.whl
| Download URL | sphinx_autostub-0.2.0-py3-none-any.whl |
|---|---|
| Size | 12.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
8c065c7d6dc851eb5c66555c7d0d829df65cd2d7c77dd8e0fc11ad3fba89f392
|
|
BLAKE2b-256 checksum How to use checksums |
f82a6bf4b16c46b49029e514927d90c87c296f6152c83188ebc57003109698a1
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.13.9
|