views:

752

answers:

4

Hi,

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.
A: 

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).

iElectric
Would automodule document classes and function in it? It isn't doing it here.
Adam Matan
It will, you just need to read documentation of Sphinx more carefully. All directives accept special parameters to make them behave as you want.
iElectric
Can you please elaborate or link?
Adam Matan
+9  A: 

We use

.. autmodule:: module
   :members:
S.Lott
Great! Any idea how to tell Sphinx to display ALL members, not just those having docstrings? Can you link me to a source on the matter? Thanks!
Adam Matan
Everything is written here: http://sphinx.pocoo.org/ext/autodoc.htmlInshort: add :undoc-members:
iElectric
+2  A: 

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.

Bastien Léonard
I prefer the look, feel and flexibility of Sphinx...
Adam Matan
+3  A: 

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.

Etienne