Sphinx extension to autodoc traitlets
Project description
autodoc-traits
autodoc-traits
is a Sphinx extension that builds on sphinx.ext.autodoc
to better document classes with Traitlets based configuration.
autodoc-traits
provides the Sphinx directives autoconfigurable
(use with
classes) and autotrait
(use with the traitlets based configuration options).
The sphinx.ext.autodoc
provided directive [automodule
][], which can overview
classes, will with autodoc-traits
enabled use autoconfigurable
over
autoclass
for classes has trait based configuration. Similarly, the
sphinx.ext.autodoc
provided autoclass
directive will use autotrait
over
autoattribute
if configured to present the traitlets attributes normally
not presented.
The autoattribute
directive will provide a header looking like trait c.SampleConfigurable.trait = Bool(False)
, and as docstring it will use the
trait's configured help text.
How to use it
-
Install
autodoc-traits
:pip install autodoc-traits
-
Configure Sphinx to use the
autodoc_traits
extensions in a Sphinx project'sconf.py
file:# -- General Sphinx configuration -------------------------------------------- # ref: https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # extensions = [ "autodoc_traits", # sphinx.ext.autodoc will be registered by autodoc_traits, # but can safely be registered again. # ... ]
-
Make use of the
sphinx.ext.autodoc
Sphinx directive likeautomodule
that document classes, theautodoc_traits
providedautoconfigurable
that documents traitlets configurable classes, or theautodoc_traits
providedautotrait
that documents individual traitlets configuration options:From a .rst document:
.. automodule:: sample_module :members: .. autoconfigurable:: sample_module.SampleConfigurable .. autotrait:: sample_module.SampleConfigurable.trait
Use with MyST Parser
While you can use myst-parser
, sphinx.ext.autodoc
's directives emits
unparsed rST, forcing us to parse the autodoc directives in a rST context.
From a .md document, with myst-parser
:
```{eval-rst}
.. autoconfigurable:: sample_module.SampleConfigurable
```
Due to this, also the Python docstrings are required to be in rST as well. Addressing this can be tracked from executablebooks/team-compass issue #6.
Project details
Release history Release notifications | RSS feed
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
File details
Details for the file autodoc_traits-1.2.2.tar.gz
.
File metadata
- Download URL: autodoc_traits-1.2.2.tar.gz
- Upload date:
- Size: 16.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | a42bc8a78fe95cffb84bdb30b301368347442666ae6f9543304c566761d6a91c |
|
MD5 | 3bd9b12fb6ea5276b2010ef371e91b21 |
|
BLAKE2b-256 | 26ca8837edecbfa7ca4640a063249422ca5b1431694d3d7f1b06be8879fce498 |
File details
Details for the file autodoc_traits-1.2.2-py3-none-any.whl
.
File metadata
- Download URL: autodoc_traits-1.2.2-py3-none-any.whl
- Upload date:
- Size: 7.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.0.0 CPython/3.12.3
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | f26c5e942745c3b8c5350bfdaac409fe531aca2b4639a4daaaad398e9592a1a1 |
|
MD5 | 9c708e24b18fa8f2531d4f1de3cf52cb |
|
BLAKE2b-256 | d05cc88609bd486d570ba581cc8a2dfbf7df1a7b52f96159a648c56840aa844a |