Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically create a toctree for autodoc classes in Sphinx

I'm looking to increase the documentation in one of my libraries. I've been using sphinx to help build the documentation and recently started exploring the autodoc extension.

It seems like in most professional documentation, each class documentation page has a list of all the documented methods with links at the top. Or, in other words, a toctree at the top with hyperlinks to each of the more in depth method documentation.

Is there a way to automatically create this toctree for each of the classes being documented with autodoc?

like image 465
Ben Hoff Avatar asked Jan 01 '16 16:01

Ben Hoff


People also ask

What is Toctree?

The toctree directive is the central element. Note. Simple “inclusion” of one file in another can be done with the include directive. Note. To create table of contents for current document (.


1 Answers

In your conf.py file for sphinx add

extensions = ['sphinx.ext.autosummary',]
# NOTE: Don't overwrite your old extension list! Just add to it!

autodoc_default_flags = ['members']
autosummary_generate = True

I put the toctree in my index.rst, and it looks like this:

.. autosummary::
     :toctree: stubs

     Class1
     Class2
     Class3

See this example for the conf.py settings

and this example for an example of the toctree.

Hope that helps!

like image 77
Ben Hoff Avatar answered Nov 15 '22 18:11

Ben Hoff