Question

This is a generalized version of a previous question regarding Sphinx.

Is there a way to recursively autodocument modules or packages which contain classes and functions within them?

I think it is silly to add the autofunction or automodule directive for each function; There must be a way to automate the process, otherwise I don't see the point of using Sphinx at all.

Clarification: Instead of :

.. automodule:: segments.segments

    .. autoclass:: segments.segments.Seg

        .. automethod:: Seg.method_1

        .. automethod:: Seg.method_2

        .. automethod:: Seg.method_3

        .......

        .. automethod:: Seg.method_n

Which requires me to manually cut-and-paste all method names and update the documentation correspondingly, I want to have a command like:

.. automodule:: segments.segments

    .. autoclass:: segments.segments.Seg

        .. MAGIC COMMAND: Automatically print the docstrings and signatures 
           of all Seg() methods.
Was it helpful?

Solution

We use

.. automodule:: module
   :members:

OTHER TIPS

To make things easier you can use this script (look at the bottom of the page for the last version): http://bitbucket.org/birkenfeld/sphinx/issue/98/add-the-autogenerate-script-to-sphinx

This script will parse your packages/modules and generate all the rest files necessary to build the doc from docstrings.

I'm the original author of this script.

UPDATE

This script is now part of Sphinx 1.1 as apidoc.

Etienne's script, mentioned in his answer, has now been integrated into Sphinx as sphinx-apidoc. It does exactly what the OP wants. It is slated for release in Sphinx 1.1, or is available from the Hg repo:

https://bitbucket.org/birkenfeld/sphinx

It works beautifully for me. The docs read thus:

> sphinx-apidoc --help
Usage: sphinx-apidoc-script.py [options] -o <output_path> <module_path>
           [exclude_paths, ...]

Look recursively in <module_path> for Python modules and packages and create
a reST file with automodule directives per package in the <output_path>.

I think it is silly to add the autofunction or automodule directive for each function; There must be a way to automate the process, otherwise I don't see the point of using Sphinx at all.

I would suggest Epydoc, which is specialized at generating documentation from docstrings.

You want it more simpler than just specifing automodule? Even for a large library, it's 5min amount of work to type all the module names.

The reason of doing so is because Sphinx hardly guesses what needs to be documented.

You could also write autopackage, that would search for modules and use automodule directive (if automodule does not do that already).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top