sphinx-doc / sphinx

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

Functions and Classes appear as submodule (autodoc, python) #11180

Open spreiter opened 1 year ago

spreiter commented 1 year ago

Describe the bug

In our project we use autodoc. After updating Sphinx to >=5.2 one package is messed up. In its sub packages and sub modules not only the single modules are listed, but also all functions, classes etc.

Part of config:

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

extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.todo',
    'sphinx.ext.viewcode',
    'sphinx.ext.intersphinx',
    'sphinx.ext.napoleon',
    'sphinxarg.ext',
    'sphinxext.custom_roles',
]
templates_path = ['_templates']
source_suffix = '.rst'
master_doc = 'index'
language = 'en'

autodoc_default_options = {
    'members': True,
    'member-order': 'bysource',
    'special-members': '', #'__init__',
    'private-members': True,
    'undoc-members': True,
    'inherited-members': True,
    'show-inheritance': True,
    'exclude-members': 'return_parser'
}

Our folder structure looks like this:

/calibration
/doc
/lib
  - asics.py
  - analysis_utils.py
  - ...

and the HTML of lib looks like this:

lib

I have the impression that his is related to #6316, but not sure.

How to Reproduce

source/index.rst:

.. documentation master file, created by
   sphinx-quickstart on Fri Jun 21 11:48:28 2019.
   You can adapt this file completely to your liking, but it should at least
   contain the root `toctree` directive.

Welcome to documentation!
=====================

Contents:

.. toctree::
   :maxdepth: 2
   :titlesonly:

   Libraries <lib>
   Calibrations <calibrations>

Indices and tables
==================

* :ref:`genindex`
* :ref:`modindex`
* :ref:`search`

command: in the /doc folder:

sphinx-build -b html -d build/doctrees source build/html

Environment Information

Platform:              linux; (Linux-4.18.0-425.3.1.el8.x86_64-x86_64-with-redhat-7.9-Nitrogen)
Python version:        3.6.8 (default, Nov 10 2020, 07:30:01) 
[GCC 4.8.5 20150623 (Red Hat 4.8.5-44)])
Python implementation: CPython
Sphinx version:        5.3.0
Docutils version:      0.18.1
Jinja2 version:        3.0.3

Sphinx extensions

No response

Additional context

No response

ShawnHymel commented 1 year ago

I'm also running into this problem. Any time there's more than one class in a module or non-method functions, those attributes show up as separate "submodules" in the package listing. Any help would be appreciated!

ShawnHymel commented 1 year ago

As I'm using sphinx-apidoc, the workaround for me seems to be to NOT include the --no-headings option and find another way to modify the headers in each file (e.g. through a callback in conf.py or by another script that cleans the final pages).

spreiter commented 2 months ago

I finally once again annoyed by this, so I checked each commit in the release branch. It turns out to be f57177de89ff1a154c830558d218c3e334b2b437 , which sums up the changes introduced by #10807. I will ask there, maybe someone has an idea.

Turns out that the config needs to be adjusted to fix this ^1.

toc_object_entries = False
Yuhi-Aoki commented 2 months ago

@spreiter I have a same issue, but

toc_object_entries = False

is not working in my project.

Could you tell me detail how to hidden about submodules and packages in toc

FYI conf.py

import os
import sys

sys.path.insert(0, os.path.abspath("../"))
sys.path.insert(0, os.path.abspath("../src/"))

project = "model-proj"
release = "1.0.0"

extensions = ["sphinx.ext.autodoc", "myst_parser"]

templates_path = ["_templates"]

language = "ja"

html_theme = "sphinx_rtd_theme"
html_static_path = ["_static"]
# hidden submodules headings
toc_object_entries = False

shell command

sphinx-apidoc -f -o source ../ && make html
spreiter commented 2 months ago

Hi @Yuhi-Aoki ,

Not sure, whether this helps, but maybe try to toc level:

html_theme_options = {
    'globaltoc_maxdepth': 0,
}

And if you want to exclude certain submodules or folders, you can specify those during the shell command:

sphinx-apidoc -f  -o source ../ [PATH-TO-EXCLUDE ...]

Cheers