53

I am trying to automatically create api docs for a large python codebase using Sphinx.

I have tried using build_modules.py and sphinx-apidoc. With either one, I can get rst docs successfully created in my output directory for the packages and top-level modules.

However, when I build using

make html

it gives thousands of errors of this type:

<autosummary>:None: WARNING: toctree contains reference to nonexisting document 'rstDocs/src.Example1.class1.method1'

for every single class and method in the codebase. With some experimentation I think I have discovered that the autosummary/autoclass directives are creating toctrees that expect there to be rst files for every class and method.

Other than the warnings, the documentation seems to work well, but I would like to get rid of them and I think I may have misconfigured something.

I have also tried nipype/tools to much the same effect.

I modified apigen.py and build_modref_templates.py to create rst stubs for each of these "missing" documents, with autoclass/autofunction/automethods as appropriate. However, the build takes quite a long time (10 minutes) and eventually crashes due to memory errors on the last build step.

Here is an example module rst file that creates all the warnings:

src Package
===========

:mod:`src` Package
------------------

.. automodule:: src.__init__
    :members:
    :undoc-members:
    :show-inheritance:

:mod:`Example1` Module
------------------------------------

.. automodule:: src.Example1
    :members:
    :undoc-members:
    :show-inheritance:

:mod:`Example2` Module
------------------

.. automodule:: src.Example2
    :members:
    :undoc-members:
    :show-inheritance:

Thanks for any advice on how to make these warnings resolve! I would like to stay away from any solution that involves modifying the sphinx site-package files.

bad_coder
  • 11,289
  • 20
  • 44
  • 72
user1287170
  • 713
  • 1
  • 6
  • 8
  • Are you sure you have a toctree entry pointing to the generated docs? e.g. to the `src` package documentation you posted above? – Kevin Horn Dec 07 '12 at 15:12
  • Related unresolved issue: https://github.com/numpy/numpydoc/issues/69 – taper Jun 20 '18 at 02:13

4 Answers4

44

Sorry for such a late answer (if it can be considered that) but I found this link that discusses what may be happening to you:

https://github.com/phn/pytpm/issues/3#issuecomment-12133978

The idea that if you have some special Doc scraper in your documentation code that is building autosummary documentation after autosummary has already run may be something to look into if you are still having this issue. Although, I'm not sure how much help this will be.

The key from the link is to add: numpydoc_show_class_members = False to conf.py

Martin Thoma
  • 124,992
  • 159
  • 614
  • 958
djhoese
  • 3,567
  • 1
  • 27
  • 45
  • 3
    If you do that, that removes the method table, though :( – Andreas Mueller Oct 27 '16 at 19:43
  • 1
    Has anyone discovered a solution that doesn't remove the method table? I cannot switch to `sphinx.ext.napoleon` because that does not seem to support the same feature as `numpydoc_use_plots`. – Aaron Voelker May 24 '17 at 22:57
  • > Has anyone discovered a solution that doesn't remove the method table? Yes, copy the matplotlib/sphinxext/plot_directive.py into your doc local directory and use that as an additional sphinx directive. – Alex Kaszynski Jun 27 '21 at 03:56
19

I just encountered this issue too and spend hours on this, The following worked for me:

Sphinx can be fussy, and sometimes about things you weren’t expecting. For example, you well encounter something like:

WARNING: toctree contains reference to nonexisting document u'all-about-me'
...
checking consistency...
<your repository>/my-first-docs/docs/all-about-me.rst::
WARNING: document isn't included in any toctree'

Quite likely, what has happened here is that you indented all-about-me in your .. toctree:: with four spaces, when Sphinx is expecting three.

Source: docs!

jpihl
  • 7,941
  • 3
  • 37
  • 50
0x78f1935
  • 465
  • 6
  • 10
11

If you are using the numpydoc extension, you could consider removing it and using sphinx.ext.napoleon instead.

Since version 1.3, Numpy and Google style docstrings are in fact supported by this builtin extension.

Removing numpydoc and using sphinx.ext.napoleon in your conf.py will therefore probably solve your problem.


Sources

Kurt Bourbaki
  • 11,984
  • 6
  • 35
  • 53
1

In Sphinx 5.3, your indentation needs to be consistent (the number of spaces does not seem to matter).

Three space indentation will work:

.. toctree::
   :maxdepth: 2
   :caption: Contents:

   admin/index

Two space indentation will also work:

.. toctree::
  :maxdepth: 2
  :caption: Contents:

  admin/index

However if the indentation is inconsitent, with :maxdepth: indented with three spaces, but admin/index indented with two spaces as shown below...

.. toctree::
   :maxdepth: 2
   :caption: Contents:

  admin/index

...then you will likely get warnings:

WARNING: toctree contains reference to nonexisting document ' :maxdepth: 2'
WARNING: toctree contains reference to nonexisting document ' :caption: Contents:' 
w. Patrick Gale
  • 1,643
  • 13
  • 22