Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
smite opened this issue Mar 5, 2021 · 5 comments
Open

Comments

@smite
Copy link

smite commented Mar 5, 2021

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']
@smite smite added the type:bug label Mar 5, 2021
@byrdie
Copy link

byrdie commented Mar 4, 2022

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
Copy link

Also found this issue.

@MCRE-BE
Copy link

MCRE-BE commented Aug 12, 2022

Same issue

@AA-Turner AA-Turner added this to the some future version milestone Sep 29, 2022
guyer added a commit to guyer/fipy that referenced this issue Aug 8, 2023
Importing part of a package within itself causes
[autosummary weirdities](sphinx-doc/sphinx#8963)
guyer added a commit to usnistgov/fipy that referenced this issue Oct 6, 2023
* Guard examples against running on import

    Examples should not run when building docs

* Change paths so Sphinx builds canonically in documentation/ dir

* Account for NaN deviation in plots

    Single points have no standard deviation? Used to work, but no more

* Move index files to Sphinx source directory

* Move Sphinx content into Sphinx source directory

* Rename AbstractCommWrapper to CommWrapper

* Move figures into Sphinx source directory

* Remove py:attr reference to target `self.vars[0]`

* Fix name of `array_like`

* Fix deprecations

* Fix targets in doc strings

* Fix typos

* Add base classes to `__all__` for documentation cross-links

* Fix name of base class

* Stop indexing explicit examples

    Some examples now appear in two locations
    [TODO: Sorting that out is misery for another day]
    - in the explicit list of examples
    - in the examples API documentation
    Loud warnings if we try to index both, so only index the API variant.

* Simplify API toctree

* Clear up root of examples documentation

* Fix tutorial documentation toctree

* Add mock imports for solvers that probably aren't installed

* Update intersphinx mappings

* Stop generating autosummary for examples

    Examples are referred to explicitly and in API.
    Don't need autosummary, too?

* Fix broken links

* Remove references to obsolete classes

* Make module name legal

* Fix typo

* Fix target type

* Make labels unique

* Link to examples in API documentation

    Removes duplicate entries

* Explicitly denote "single" index entries

    The
    ["shorthand" notation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-index)
    raises lots of spurious warnings about
    `Explicit markup ends without a blank line; unexpected unindent.`

* Fix path to included file

* Ignore modules file

* Specify attribute path

* Fix markup of combined attribute

* Fix duplicate footnotes

* Update instructions for building documentation

    Much changes when using Sphinx's canonical `make html`.

* Remove build_docs command from setup

* Stop hiding api docs

* Fix crosslink to updating instructions

* Fix broken links

* Fully specify inherited object to document

* Mute Mayavi documentation issues

* Fix target reference for factory method

* Move ElPhF documentation from TeX to module docstring

* Change target type for Python standard types

    :keyword:`dict` links to
    https://docs.python.org/3/reference/expressions.html#dict
    but :keyword:`list` doesn't link to
    https://docs.python.org/3/reference/expressions.html#list-displays
    ?

    :class:`dict`, :class:`list`, and :class:`tuple` are more
    appropriate, anyway.

* Don't nitpick references to files and the like

* Remove arcane `__all__.extend`

    Rely on public imports for public API

* Distinguish pyAMG LU from SciPy LU

* Fix references to objects no longer in Brobdingnagian `__all__`

* Document generic solver classes

* Activate de-coupled binary phase field example

* Fix LaTeX glitches of long standing

* Migrate machinery from for turning .rst into .tex inputs

    Not sure this belongs in conf.py,
    but don't know where else it belongs

* Move LaTeX formatting into a .sty file

* Move documentation into separated layout

    Separate source and build directories is what
    [Sphinx seems to prefer](https://www.sphinx-doc.org/en/master/tutorial/getting-started.html#creating-the- 
   documentation-layout).

* Wrap lines and have apidoc process examples

* Point workflow to new location of docs

* Update action inputs

* Move requirements.txt into docs folder

    This is where sphinx-action (and, now, NISTtheDocs2Death)
    are looking for it.

* Create directory for generated output

* Wrap commands with parentheses

* Use line-continuing backslashes

* Require fipy in order to build fipy docs

* Look for packages one level up

* Remove obsolete action input

* Switch API documentation to autosummary

* Change imports to avoid Sphinx bug

    Importing part of a package within itself causes
    [autosummary weirdities](sphinx-doc/sphinx#8963)

* Move docstring to class from __init__

    Shouldn't be necessary, because `autoclass_content = "both"` is set...

* Update version

* Install git

* Bump version of ntd2d

* Skip numpy 1.25 dispatch functions

* Silence Sphinx autosummary errors

    Documented some items, hid others.

    `autosummary <https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html>`_
    and/or `autodoc <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
    really didn't like "`matplotlibViewer/matplotlibViewer`".
    Possibly related to sphinx-doc/sphinx#11362 ?

* Add module docstrings

* Add pip requirements

* Stop building docs (badly) on Azure

* Install git with apt-packages

* Make workdirectory a git safe.directory

* Add badges for GH Actions

* Remove Codacy badge

    Codacy is no longer free

* Fix conda-forge badge

* Switch docs pre-requisites to conda

* Update badges on static index.html

* Install self with conda from parent directory
* Fix reST

* Remove depsy badge

    Project hasn't been maintained in five years and badge is broken
    (because it's only available as an http:// link in an https:// page?)

* Add mock imports for petsc4py, mpi4py, and mayavi

* Update searchbox to be consistent with basic theme

* Add more mock imports

* Add intersphinx mapping for mayavi

* Stop using "is" and "is not" to compare with literals

    Addresses #891

* Fix spelling

* Fix renaming missed in 819fbfa

* Switch from mamba to conda in Py2.7

* Ensure logging is configured

* Fix unicode module contents for Py2.7

* Fix typo

Co-authored-by: Trevor Keller <trevor.keller@nist.gov>

* Add brief explanation of each chunk of examples

* Make multiline pre-build-command "chomping"

* Convert rst to tex with make

* Generate PDF

* Remove file conversion from configuration

* Make Makefile more makey

* Collapse examples into a single chapter

Co-authored-by: Trevor Keller <trevor.keller@nist.gov>
guyer added a commit to usnistgov/fipy that referenced this issue Oct 6, 2023
Clean up legacy Sphinx hacks and resolve longstanding warnings.

Support use of NISTtheDocs2Death to put documentation on
https://pages.nist.gov/fipy.

Previous configuration went to great lengths to "see" things
outside documentation directory, which is not the intended
design of sphinx. Using autodoc instead of autosummary simplifies
things considerably.

* Guard examples against running on import

    Examples should not run when building docs

* Change paths so Sphinx builds canonically in documentation/ dir

* Account for NaN deviation in plots

    Single points have no standard deviation? Used to work, but no more

* Move index files to Sphinx source directory

* Move Sphinx content into Sphinx source directory

* Rename AbstractCommWrapper to CommWrapper

* Move figures into Sphinx source directory

* Remove py:attr reference to target `self.vars[0]`

* Fix name of `array_like`

* Fix deprecations

* Fix targets in doc strings

* Fix typos

* Add base classes to `__all__` for documentation cross-links

* Fix name of base class

* Stop indexing explicit examples

    Some examples now appear in two locations
    [TODO: Sorting that out is misery for another day]
    - in the explicit list of examples
    - in the examples API documentation
    Loud warnings if we try to index both, so only index the API variant.

* Simplify API toctree

* Clear up root of examples documentation

* Fix tutorial documentation toctree

* Add mock imports for solvers that probably aren't installed

* Update intersphinx mappings

* Stop generating autosummary for examples

    Examples are referred to explicitly and in API.
    Don't need autosummary, too?

* Fix broken links

* Remove references to obsolete classes

* Make module name legal

* Fix typo

* Fix target type

* Make labels unique

* Link to examples in API documentation

    Removes duplicate entries

* Explicitly denote "single" index entries

    The
    ["shorthand" notation](https://www.sphinx-doc.org/en/master/usage/restructuredtext/directives.html#directive-index)
    raises lots of spurious warnings about
    `Explicit markup ends without a blank line; unexpected unindent.`

* Fix path to included file

* Ignore modules file

* Specify attribute path

* Fix markup of combined attribute

* Fix duplicate footnotes

* Update instructions for building documentation

    Much changes when using Sphinx's canonical `make html`.

* Remove build_docs command from setup

* Stop hiding api docs

* Fix crosslink to updating instructions

* Fix broken links

* Fully specify inherited object to document

* Mute Mayavi documentation issues

* Fix target reference for factory method

* Move ElPhF documentation from TeX to module docstring

* Change target type for Python standard types

    :keyword:`dict` links to
    https://docs.python.org/3/reference/expressions.html#dict
    but :keyword:`list` doesn't link to
    https://docs.python.org/3/reference/expressions.html#list-displays
    ?

    :class:`dict`, :class:`list`, and :class:`tuple` are more
    appropriate, anyway.

* Don't nitpick references to files and the like

* Remove arcane `__all__.extend`

    Rely on public imports for public API

* Distinguish pyAMG LU from SciPy LU

* Fix references to objects no longer in Brobdingnagian `__all__`

* Document generic solver classes

* Activate de-coupled binary phase field example

* Fix LaTeX glitches of long standing

* Migrate machinery from for turning .rst into .tex inputs

    Not sure this belongs in conf.py,
    but don't know where else it belongs

* Move LaTeX formatting into a .sty file

* Move documentation into separated layout

    Separate source and build directories is what
    [Sphinx seems to prefer](https://www.sphinx-doc.org/en/master/tutorial/getting-started.html#creating-the-
   documentation-layout).

* Wrap lines and have apidoc process examples

* Point workflow to new location of docs

* Update action inputs

* Move requirements.txt into docs folder

    This is where sphinx-action (and, now, NISTtheDocs2Death)
    are looking for it.

* Create directory for generated output

* Wrap commands with parentheses

* Use line-continuing backslashes

* Require fipy in order to build fipy docs

* Look for packages one level up

* Remove obsolete action input

* Switch API documentation to autosummary

* Change imports to avoid Sphinx bug

    Importing part of a package within itself causes
    [autosummary weirdities](sphinx-doc/sphinx#8963)

* Move docstring to class from __init__

    Shouldn't be necessary, because `autoclass_content = "both"` is set...

* Update version

* Install git

* Bump version of ntd2d

* Skip numpy 1.25 dispatch functions

* Silence Sphinx autosummary errors

    Documented some items, hid others.

    `autosummary <https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html>`_
    and/or `autodoc <https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html>`_
    really didn't like "`matplotlibViewer/matplotlibViewer`".
    Possibly related to sphinx-doc/sphinx#11362 ?

* Add module docstrings

* Add pip requirements

* Stop building docs (badly) on Azure

* Install git with apt-packages

* Make workdirectory a git safe.directory

* Add badges for GH Actions

* Remove Codacy badge

    Codacy is no longer free

* Fix conda-forge badge

* Switch docs pre-requisites to conda

* Update badges on static index.html

* Install self with conda from parent directory
* Fix reST

* Remove depsy badge

    Project hasn't been maintained in five years and badge is broken
    (because it's only available as an http:// link in an https:// page?)

* Add mock imports for petsc4py, mpi4py, and mayavi

* Update searchbox to be consistent with basic theme

* Add more mock imports

* Add intersphinx mapping for mayavi

* Stop using "is" and "is not" to compare with literals

    Addresses #891

* Fix spelling

* Fix renaming missed in 819fbfa

* Switch from mamba to conda in Py2.7

* Ensure logging is configured

* Fix unicode module contents for Py2.7

* Fix typo

Co-authored-by: Trevor Keller <trevor.keller@nist.gov>

* Add brief explanation of each chunk of examples

* Make multiline pre-build-command "chomping"

* Convert rst to tex with make

* Generate PDF

* Remove file conversion from configuration

* Make Makefile more makey

* Collapse examples into a single chapter

Co-authored-by: Trevor Keller <trevor.keller@nist.gov>
@Naggafin
Copy link

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
Copy link

emolter commented May 13, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants