Skip to main content

sphinxter

Autodoc converting YAML docstrings and code comments to sphinx documentation

Formatting

I wanted something that generated readable HTML documentation from readable Code documentation.

Even if you've done nothing to your code to use sphinxter, it'll generate decent documentation assuming non YAML docstrings are descriptions for their resources.

Say this is yourmodule

"""
The module description
"""

foo = None # The foo description

def func(
    bar:int # The bar description
)->bool:
    """
    The function description
    """

This would be the result in docs/source/index.rst:

.. created by sphinxter
.. default-domain:: py

yourmodule
==========

.. module:: yourmodule

The module description

.. attribute:: foo

    The foo description

.. function:: func(bar: int)

    The function description

    :param bar: The bar description
    :type bar: int
    :rtype: bool

Not only is this decent documentation, sphinxter picked up the comments next to both attributes and function parameters, which is a very common, readable pattern in code.

Another useful couple of features is that sphinxter can read dosctrings as YAML and it can read attributes docstrings (which yes, don't really exist, but it works anyway) allowing for some complex but still readable behavior.

Say this is yourmodule now:

"""
The module description
"""

foo = None # The foo description
"""
usage: |
    Do it this way::

        yourmodule.foo = 7
"""

def func(
    bar:int # The bar description
)->bool:
    """
    description: The function description
    return: Whether the function worked or not
    """

This would now be the result in docs/source/index.rst:

.. created by sphinxter
.. default-domain:: py

yourmodule
==========

.. module:: yourmodule

The module description

.. attribute:: foo

    The foo description

    **Usage**

    Do it this way::

        yourmodule.foo = 7

.. function:: func(bar: int)

    The function description

    :param bar: The bar description
    :type bar: int
    :return: Whether the function worked or not
    :rtype: bool

Taking advantage of attribute docstrings and YAML docstrings added more documentation, but didn't really lessen the readability of the code.

That's the goal of sphinxter.

Organization

By default, everything ends up in the index.rst document. With modules, classes, and functions you can a different document and even the order in which they'll appear in the document. If the parent modules don't match, sphinxter will add a currentmodule directive so everything will be organized properly.

Setup

To setup a package to use sphinxter:

  1. Install sphinxter (which includes sphinx)
    pip install sphinxter
  1. Setup documentation area as docs/source:
    sphinx-quickstart docs --sep -p yourmodule -a 'Your Name' -r yourversion -l en
  1. Create a script docs.py like so:
    #!/usr/bin/env python

    import sphinxter
    import yourmodule

    sphinxter.Sphinxter(yourmodule).process()
  1. Run that script to auto generate docs from your docstrings (they'll end up in docs/source):
    chmod a+x docs.py
    ./docs.py
  1. Create HTML from those documents (they'll end up in docs/build/html):
    sphinx-build -b html docs/source/ docs/build/html

Release files for sphinxter 0.1.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sphinxter 0.1.8
File Size Uploaded
sphinxter-0.1.8.tar.gz 24.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sphinxter 0.1.8
File Interpreter ABI Platform
sphinxter-0.1.8-py3-none-any.whl Python 3 none any Details

Total release size: 50.7 kB

Release files / sphinxter-0.1.8.tar.gz

Download URL sphinxter-0.1.8.tar.gz
Size 24.9 kB
Tags Source
SHA-256 checksum
How to use checksums
03899c70054714cf1b3f26ae04009398f900158318a8b2324da38e7134e27ac7
BLAKE2b-256 checksum
How to use checksums
829f0d74923ce50d75b7463faac074e4c9e199c45da65ada5170bf226fdc6e74
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Release files / sphinxter-0.1.8-py3-none-any.whl

Download URL sphinxter-0.1.8-py3-none-any.whl
Size 25.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
41fbb23dc071fdeaa603e968890a3837d1b7220375b662c30a62072ecd5e60ed
BLAKE2b-256 checksum
How to use checksums
3dff2f3a91ce3319503ee70b5454258514972f7e4943df934118af4029e3dba1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.5

Release history Release notifications | RSS feed

This release

0.1.8 This release

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page