12

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.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
viraptor
  • 33,322
  • 10
  • 107
  • 191

2 Answers2

2

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:
viraptor
  • 33,322
  • 10
  • 107
  • 191
0

I am seeing three possible causes for this to happen:

  • Sphinx's cache is causing trouble, and make clean would solve the issue
  • Your module is located in a package, and the package's __init__.py file is importing these "other files" (or to be more accurate is trying to import them);
  • These "other files" are imported because you have set PYTHONSTARTUP
lgautier
  • 11,363
  • 29
  • 42