Skip to main content

Autodoc converting YAML docstrings and code comments to sphinx documentation

Project description

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

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

sphinxter-0.1.8.tar.gz (24.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sphinxter-0.1.8-py3-none-any.whl (25.8 kB view details)

Uploaded Python 3

File details

Details for the file sphinxter-0.1.8.tar.gz.

File metadata

  • Download URL: sphinxter-0.1.8.tar.gz
  • Upload date:
  • Size: 24.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for sphinxter-0.1.8.tar.gz
Algorithm Hash digest
SHA256 03899c70054714cf1b3f26ae04009398f900158318a8b2324da38e7134e27ac7
MD5 bd3c7754a82973173eacf61935ce6bbb
BLAKE2b-256 829f0d74923ce50d75b7463faac074e4c9e199c45da65ada5170bf226fdc6e74

See more details on using hashes here.

File details

Details for the file sphinxter-0.1.8-py3-none-any.whl.

File metadata

  • Download URL: sphinxter-0.1.8-py3-none-any.whl
  • Upload date:
  • Size: 25.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.5

File hashes

Hashes for sphinxter-0.1.8-py3-none-any.whl
Algorithm Hash digest
SHA256 41fbb23dc071fdeaa603e968890a3837d1b7220375b662c30a62072ecd5e60ed
MD5 6a093cfb8a2b17dacf2add3ad5d4e999
BLAKE2b-256 3dff2f3a91ce3319503ee70b5454258514972f7e4943df934118af4029e3dba1

See more details on using hashes here.

Supported by

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