Sphinx, using automodule to find submodules

24,532

Solution 1

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

Solution 2

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.

Share:
24,532
Christopher Dorian
Author by

Christopher Dorian

Updated on June 16, 2020

Comments

  • Christopher Dorian
    Christopher Dorian about 4 years

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

  • mzjn
    mzjn over 7 years
    I don't think this is solved by using imported-members. IMHO, @devin_s's highly upvoted answer is the correct one (or at least on the right track). The asker has not been active on Stack Overflow since August 2013, so it seems unlikely that we will get a confirmation from him.
  • Noel Maersk
    Noel Maersk about 7 years
    True... Re-read question, seems that I misunderstood it, interpreting through the lens of my own task. Sorry for the noise.
  • naught101
    naught101 over 5 years
    This is a pretty old answer now. Is it still the case that there's no auto-discovery?
  • user2514157
    user2514157 about 4 years
    @naught101 see sphinx-apidoc and sphinx-autogen
  • Ivo Merchiers
    Ivo Merchiers over 3 years
    @naught101 in particular this related thread can be interesting.