Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get Sphinx autosummary to generate full API documentation for classes, as well as a *summary table* for those classes?

I'm sure this is user error at one level or another but I'm going mad slowly here and would really appreciate some help.

I've gotten both sphinx-apidoc and the excellent third party sphinx-autoapi to work, but can't repeat the trick with sphinx.ext.autosummary. It's driving me mad... plus neither of these options give you the really neat package/module member summary tables that are (presumably) the main selling point of sphinx.ext.autosummary.

I have a really simple project:

|_ TEST
   |_ docs
      |_ conf.py
      |_ index.rst
   |_ myproject
      |_ __init__.py
      |_ mymodule.py

conf.py looks like this:

import os
import sys
sys.path.insert(0, os.path.abspath('../../myproject'))

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.autosummary'
]

autosummary_generate = True

index.rst looks like this:

.. autosummary::
   :toctree: _autosummary

   myproject.mymodule

mymodule.py looks like this:

"""
Module containing a class and a function.
"""

class TestClass:
    """
    A class representing a test.

    I wish I could get this to stuff to show up but I can't and I don't know why.

    Why isn't this documentation visible?!? :-(
    """
    def __init__(self):
        """
        Instantiate.
        """
        pass

    def Func_in_test_class(self):
        """
        Cool function that does stuff.

        :return: Some new stuff.
        """
        pass

def GlobalFunc():
    """
    Utility function.

    Does some good stuff.
    """
    pass

Running make html from the docs directory makes this lovely Readthedocs-style HTML:

(see picture)

What I want to do is click on the TestClass function in the summary table and visit a new page that shows the API documentation for this class in full. How can I achieve that?

(Or am I missing the point, and I have to combine sphinx.ext.autosummary with sphinx-apidoc to get what I need..?)

like image 498
James Leedham Avatar asked May 03 '20 15:05

James Leedham


1 Answers

From Sphinx version 3.1 (June 2020), sphinx.ext.autosummary finally has recursion!

I've answered my own question here: https://stackoverflow.com/a/62613202/12014259

like image 114
James Leedham Avatar answered Sep 28 '22 00:09

James Leedham