Skip to content Skip to sidebar Skip to footer

Have Sphinx Recognize Imported Classes And Functions Instead Of Modules

Suppose I have a project with the following structure: mypackage ├── mypackage │ ├── __init__.py │ ├── someclass.py │ └── somefunction.py └─

Solution 1:

Use autoclass as described in the Sphinx documentation sphinx.ext.autodoc – Include documentation from docstrings.

In order for autoclass (and any other autodoc feature) to work, the module must be importable.

autodoc will document the API of your module, and you can add docstrings in reStructuredText format as narrative documentation to explain usage.

It's a good idea to have a docs directory next to your package directory.

mypackage
├── docs
│   ├── conf.py
│   ├── other sphinx stuff
│   └── index.rst
├── mypackage
│   ├── __init__.py
│   ├── someclass.py
│   └── somefunction.py
└── setup.py

Organize your .rst files within docs. Your module is an API, so you could organize your .rst files like so:

mypackage
├── docs
    └── api
        ├── someclass.rst
        └── somefunction.rst

In each of the files in the api directory, use the appropriate syntax.

.. autoclass:: someclass
.. autofunction:: somefunction

There's also several options covered in the aforementioned Sphinx documentation.

Post a Comment for "Have Sphinx Recognize Imported Classes And Functions Instead Of Modules"