Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sphinx, using automodule to find submodules

When using sphinx's automodule (https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html),

I simply write in a .rst file:

.. automodule:: my_module     :members: 

It documents my_module fine, but it doesn't find the inner modules like my_module.inner_module0 and my_module.inner_module1. Is there something that needs to be specified in the __init__.py file besides the __all__ variable?

Also, I'm aware of sphinx-apidoc. But that command documents far too much (exposes every function/folder including undocumented ones).

like image 914
Christopher Dorian Avatar asked Jul 16 '12 16:07

Christopher Dorian


People also ask

What does sphinx Autodoc do?

autodoc imports the modules to be documented. If any modules have side effects on import, these will be executed by autodoc when sphinx-build is run. If you document scripts (as opposed to library modules), make sure their main routine is protected by a if __name__ == '__main__' condition.

What is sphinx-Apidoc?

sphinx-apidoc is a tool for automatic generation of Sphinx sources that, using the autodoc extension, document a whole package in the style of other automatic API documentation tools. MODULE_PATH is the path to a Python package to document, and OUTPUT_PATH is the directory where the generated sources are placed.


2 Answers

It sounds like you want to give the automodule directive a package name and have it recurse into the directory and document each Python module. That isn't supported yet. You will ned to specify the full dotted module name for each module you want to document.

For example, given the following directory structure (from the Python documentation). You cannot specify .. automodule:: sound.formats and have it document all the modules in the directory. You will have to specify a automodule command for each module: .. automodule:: sound.formats.waveread, .. automodule:: sound.formats.wavewrite, etc.

sound/                          Top-level package       __init__.py               Initialize the sound package       formats/                  Subpackage for file format conversions               __init__.py               wavread.py               wavwrite.py               aiffread.py               aiffwrite.py               auread.py               auwrite.py               ...       effects/                  Subpackage for sound effects               __init__.py               echo.py               surround.py               reverse.py               ... 
like image 110
devin_s Avatar answered Sep 19 '22 14:09

devin_s


It seems to me that using the :imported-members: option (non-direct link, do use search) should now be possible, if __init__.py imports those submodules.

However, I'm personally not able to make this work (yet).

EDIT: Possibly a known bug.

like image 27
Noel Maersk Avatar answered Sep 21 '22 14:09

Noel Maersk