Unable to generate html documentation for nested python modules using sphinx

70 Views Asked by At

I am using sphinx to automatically generate htmls using docstring from my python modules. For this, I am using sphinx's docker image named 'sphinxdoc/sphinx'. I run sphinx by mapping my python project (in DocString_Project directory) as a volume. Steps as follows.

  1. quickstart: docker run -it --rm -v /path/to/project/DocString_Project:/docs sphinxdoc/sphinx sphinx-quickstart

  2. edit conf.py file as:

import sys
sys.path.insert(0, os.path.abspath('../allmodules'))

extensions = ['sphinx.ext.autodoc',
       'sphinx.ext.viewcode'
]

  1. Generate .rst files.
docker run --rm -v /path/to/project/DocString_Project:/docs sphinxdoc/sphinx sphinx-apidoc -o /docs/source ../docs/allmodules
  1. This generates .rst files as shown below.

  2. Add modules below index.rst toctree::

  3. make html

docker run --rm -v /path/to/project/DocString_Project:/docs sphinxdoc/sphinx make html

Problem The generated HTML documentation correctly shows docstrings for outermost modules; docstring.py and sphinxtutorial.py but does not show documentation for any of the nested modules inside nested1 and nested2. However, sphinx apidoc does detect their presence.

Folders
DocString_Project:
------build
------source
      --------conf.py
      --------index.rst
      --------modules.rst
      --------allmodules.rst
      --------allmodules.nested1.rst
      --------allmodules.nested1.nested2.rst
------make.bat
------Makefile
------allmodules
      --------__init__.py
      --------docstring.py
      --------sphinxtutorial.py
      --------nested1
              -------- __init__.py
              -------- docstringnested1.py
              -------- sphinxtutorialnested1.py
              -------- nested2
                       --------__init__.py
                       --------docstringnested2.py
                       --------sphinxtutorialnested2.py
 

How can I show documentation from modules under nested1 and nested2?

Note: The nested py modules are exactly same as their counterparts in the parent directory, i.e. docstring.py is same as docstringnested1.py and docstringnested2.py

Updated: Contents for .rst files: allmodules.rst

==================

Subpackages
-----------

.. toctree::
   :maxdepth: 4

   allmodules.nested1

Submodules
----------

allmodules.docstring module
---------------------------

.. automodule:: allmodules.docstring
   :members:
   :undoc-members:
   :show-inheritance:

allmodules.sphinxtutorial module
--------------------------------

.. automodule:: allmodules.sphinxtutorial
   :members:
   :undoc-members:
   :show-inheritance:

Module contents
---------------

.. automodule:: allmodules
   :members:
   :undoc-members:
   :show-inheritance:

allmodules.nested1.rst

allmodules.nested1 package
==========================

Subpackages
-----------

.. toctree::
   :maxdepth: 4

   allmodules.nested1.nested2

Submodules
----------

allmodules.nested1.docstringnested1 module
------------------------------------------

.. automodule:: allmodules.nested1.docstringnested1
   :members:
   :undoc-members:
   :show-inheritance:

allmodules.nested1.sphinxtutorialnested1 module
-----------------------------------------------

.. automodule:: allmodules.nested1.sphinxtutorialnested1
   :members:
   :undoc-members:
   :show-inheritance:

Module contents
---------------

.. automodule:: allmodules.nested1
   :members:
   :undoc-members:
   :show-inheritance:

allmodules.nested1.nested2.rst

allmodules.nested1.nested2 package
==================================

Submodules
----------

allmodules.nested1.nested2.docstringnested2 module
--------------------------------------------------

.. automodule:: allmodules.nested1.nested2.docstringnested2
   :members:
   :undoc-members:
   :show-inheritance:

allmodules.nested1.nested2.sphinxtutorialnested2 module
-------------------------------------------------------

.. automodule:: allmodules.nested1.nested2.sphinxtutorialnested2
   :members:
   :undoc-members:
   :show-inheritance:

Module contents
---------------

.. automodule:: allmodules.nested1.nested2
   :members:
   :undoc-members:
   :show-inheritance:

make html error/warnings

docker run --rm -v /Users/abhinav/PycharmProjects/DocString_Project:/docs sphinxdoc/sphinx make html
Running Sphinx v4.0.2
loading pickled environment... done
building [mo]: targets for 0 po files that are out of date
building [html]: targets for 0 source files that are out of date
updating environment: 0 added, 4 changed, 0 removed
reading sources... [ 25%] allmodules
reading sources... [ 50%] allmodules.nested1
reading sources... [ 75%] allmodules.nested1.nested2
reading sources... [100%] index

WARNING: autodoc: failed to import module 'docstring' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'sphinxtutorial' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1.docstringnested1' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1.sphinxtutorialnested1' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1.nested2.docstringnested2' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1.nested2.sphinxtutorialnested2' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
WARNING: autodoc: failed to import module 'nested1.nested2' from module 'allmodules'; the following exception was raised:
No module named 'allmodules'
/docs/source/index.rst:9: WARNING: toctree contains reference to nonexisting document ' modules'
looking for now-outdated files... none found
pickling environment... done
checking consistency... /docs/source/modules.rst: WARNING: document isn't included in any toctree
done
preparing documents... done
writing output... [ 20%] allmodules
writing output... [ 40%] allmodules.nested1
writing output... [ 60%] allmodules.nested1.nested2
writing output... [ 80%] index
writing output... [100%] modules

generating indices... genindex done
writing additional pages... search done
copying static files... done
copying extra files... done
dumping search index in English (code: en)... done
dumping object inventory... done
build succeeded, 11 warnings.

The HTML pages are in build/html.
0

There are 0 best solutions below