18

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

5 Answers 5

38

We use

.. automodule:: module :members: 
Sign up to request clarification or add additional context in comments.

2 Comments

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!
Everything is written here: sphinx.pocoo.org/ext/autodoc.html Inshort: add :undoc-members:
27

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.

Comments

16

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

1 Comment

How do I include <pre> style blocks (like the snippet of command help output above) without them being colored like a <code> block?
0

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.

1 Comment

Epydoc seems to be dead. Not being compatible with the latest docutils releases is pretty much a showstopper. sourceforge.net/tracker/…
-8

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

4 Comments

Would automodule document classes and function in it? It isn't doing it here.
It will, you just need to read documentation of Sphinx more carefully. All directives accept special parameters to make them behave as you want.
Can you please elaborate or link?
The problem with doing it manually is not the work of doing it, although that is inconvenient and repetitive. It's that it's error-prone. You are likely to miss something, and the results will be out of date whenever you change the structure of your source.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.