sphinx-doc / sphinx-doc/sphinx

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

Open
#8,963 5 comments 10 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

extensions:autosummary type:bug
Dominant language
Python
Stars
8k
Forks
2.6k
PR merge metrics
No merged PRs in 30d

Description

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

  • OS: Ubuntu 20.04
  • Python version: 3.9.1
  • Sphinx version: 3.5.1
  • Sphinx extensions: ['sphinx.ext.autodoc', 'sphinx.ext.autosummary']

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided conf.py and index.rst reproduction, including the recursive autosummary for aaa and the self-reference import in src/aaa/init.py. Run sphinx-build and inspect the generated api/aaa.rst and api/aaa.bbb.rst; done means the build emits no stub-file or toctree warnings and links aaa to aaa.bbb as expected.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
documentation
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
50/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.