I am trying to use Sphinx autosummary to document all of the classes within the directory mypackage/src/
. Sphinx is only generating proper documentation for the class constructors but none of the (public) methods inside classes. What am I doing wrong?
Project structure:
- docs/
- build/
- source/
- _static/
- generated/
- mypackage.src.file_3.ClassInsideFile3.rst
- api.rst
- conf.py
- index.rst
- usage.rst
- make.bat
- Makefile
- mypackage/
- __init__.py
- file_1.py
- file_2.py
- src/
- __init__.py
- file_3.py
- file_4.py
- tests/
- .gitignore
- poetry.lock
- pyproject.tomml
- README.md
docs/source/conf.py
:
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information
import sys
import os
sys.path.insert(0, os.path.abspath('../..'))
project = 'mypackage'
copyright = '2023 My Name'
author = 'My Name'
release = '0.1.0'
# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = ['sphinx.ext.autodoc', 'sphinx.ext.autosummary']
templates_path = ['_templates']
exclude_patterns = []
# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
html_theme = 'alabaster'
html_static_path = ['_static']
docs/source/api.rst
:
API
===
src
---
.. autosummary::
:toctree: generated
:recursive:
mypackage.src.file_3.class_inside_file_3
mypackage/src/file_3.py
:
class ClassInsideFile3:
"Docstring for the class"
def __init__(self, names: list):
"""
Initializes a ClassInsideFile3 object based on names argument
:param names: A list of names
:type names: list
"""
self.names = names
def add_name(self, name: str) -> None:
"""
Appends a new name to the list of names if it does not already exist
:param name: The name to be appended
:type name: str
"""
if name not in self.names:
self.names.append(name)
The result I get when I run sphinx-build docs/source docs/build
:
The generated file docs/source/generated/mypackage.src.file_3.ClassInsideFile3.rst
:
mypackage.src.file_3.ClassInsideFile3
=====================================
.. currentmodule:: mypackage.src.file_3
.. autoclass:: ClassInsideFile3
.. automethod:: __init__
# Why isn't it creating an auto method for `add_name`?
.. rubric:: Methods
.. autosummary::
~ClassInsideFile3.__init__
~ClassInsideFile3.add_name
Why isn't Sphinx creating an auto method for the add_name
method?
Did you try adding
:members:
under autoclass to specify you want all documented members? (cf. https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-option-automodule-members)My "standard" setting (here for automodule, but autoclass should behave in a similar way):