Skip to main content

Sphinx extension to autodoc traitlets

Project description

autodoc-traits

Latest PyPI version GitHub Discourse Gitter

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

  1. Install autodoc-traits:

    pip install autodoc-traits
    
  2. Configure Sphinx to use the autodoc_traits extensions in a Sphinx project's conf.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.
        # ...
    ]
    
  3. Make use of the sphinx.ext.autodoc Sphinx directive like automodule that document classes, the autodoc_traits provided autoconfigurable that documents traitlets configurable classes, or the autodoc_traits provided autotrait 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

autodoc_traits-1.2.1.tar.gz (16.6 kB view details)

Uploaded Source

Built Distribution

autodoc_traits-1.2.1-py3-none-any.whl (7.4 kB view details)

Uploaded Python 3

File details

Details for the file autodoc_traits-1.2.1.tar.gz.

File metadata

  • Download URL: autodoc_traits-1.2.1.tar.gz
  • Upload date:
  • Size: 16.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for autodoc_traits-1.2.1.tar.gz
Algorithm Hash digest
SHA256 9fbc526729453a017d01885dd3eb43b5dfbc5fa76fb9c3ed10c7bb818ea0071d
MD5 d331d4ef5116d2a15fae486f55981968
BLAKE2b-256 8d2effda73cd1ee44ff84af4d9e3ea8e923542c75ba24c50042ea56e18a84b16

See more details on using hashes here.

Provenance

File details

Details for the file autodoc_traits-1.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for autodoc_traits-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 31befcf6afb192f9b16d1276b537a8d477911c76e541f20d5066e3d7dcd22add
MD5 053ef17f899fbc88b84a2cff0a42e83f
BLAKE2b-256 e88b44b2aa070ed704c1ca9bf8ab0ace28cb34ec4d1b87a343bcb2a52b4c26d0

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page