sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.6k stars 2.12k forks source link

Recursive autosummary fails when a module contains a reference to itself. #8963

Open smite opened 3 years ago

smite commented 3 years ago

Describe the bug

Recursive autosummary produces broken documentation and emits a WARNING: autosummary: stub file not found message when a module contains a reference to itself.

To Reproduce

Assume a Python project with the following structure:

/home/user/project
├── docs
│   ├── conf.py
│   ├── index.rst
└── src
    └── aaa
        ├── bbb
        │   ├── __init__.py
        ├── __init__.py

Both __init__.py files contain just a module docstring.

conf.py:

import sys
sys.path.insert(0, '/home/user/project/src')

needs_sphinx = '3.5'
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary']
autosummary_generate = True

index.rst

.. autosummary::
   :toctree: api
   :recursive:

   aaa

Running sphinx-build for the above setup produces correct API docs.

However, if you add the line

import aaa.bbb

to src/aaa/__init__.py, Sphinx gives the warning

/home/user/project/docs/api/aaa.rst.rst:26: WARNING: autosummary: stub file not found 'aaa.aaa.bbb'. Check your autosummary_generate setting.

and fails to link aaa to aaa.bbb:

checking consistency... /home/user/project/docs/api/aaa.bbb.rst: WARNING: document isn't included in any toctree

Expected behavior Docs should be produced exactly as before, without warnings.

Environment info

byrdie commented 2 years ago

I am having this exact same issue. Does anyone have a workaround for this problem, or any ideas for a patch that could resolve it?

Rocamonde commented 2 years ago

Also found this issue.

MCRE-BE commented 2 years ago

Same issue

Naggafin commented 10 months ago

Does anyone have a stopgap solution for this? I saw mention of placing automodule before autosummary in #9069, however I don't think that is working for me.

emolter commented 6 months ago

The workaround that worked for me was to define __all__ = [modules, of, aaa] inside of what for this example would be src/aaa/__init__.py, so that autosummary does not attempt to search for all modules and functions, and instead just looks at __all__.