Search code examples
pythonpython-sphinxdocumentation-generationautodoc

Ignore some modules in autodoc


I'm trying to use autodoc for selected modules only. I've created a file which includes:

.. automodule:: some.specific.module
   :members:

And it gets generated correctly. Unfortunately autodoc keeps trying to parse other files too (and fails because of import errors). I know I can mock out some modules, but I want a better solution - stop sphinx from looking at them to begin with.

How can I make sure only the requested module is loaded, and not (for example) test.other.module.


Solution

  • So it turned out to be a stupid mistake. Since some tools generate a scaffold for api documentation sources, those files were left laying around and triggered bad imports.

    How this was found:

    • sphinx has multiple levels of debug logging which do not normally get activated
    • you can see which lines trigger imports by debug output like
     [autodoc] /path/to/the/doc.rst:158: input:
     .. automodule:: app.module.name
        :members: