doc build script and settings updated

This commit is contained in:
Nicolas Kruse 2025-06-06 09:04:42 +02:00
parent e30b4f1d47
commit 793b2a0ab4
3 changed files with 46 additions and 26 deletions

View File

@ -17,7 +17,7 @@ author = 'Nicolas Kruse'
# -- General configuration --------------------------------------------------- # -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration # https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration
extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_autodoc_typehints", "myst_parser"] extensions = ["sphinx.ext.autodoc", "sphinx.ext.napoleon", "sphinx_autodoc_typehints", "myst_parser", "sphinx.ext.autosummary"]
templates_path = ['_templates'] templates_path = ['_templates']
exclude_patterns = [] exclude_patterns = []
@ -26,7 +26,8 @@ exclude_patterns = []
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output # https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output
# html_theme = 'alabaster' # html_theme = 'alabaster'
html_theme = 'sphinx_rtd_theme' html_theme = 'pydata_sphinx_theme'
html_static_path = ['_static'] html_static_path = ['_static']
autodoc_inherit_docstrings = True autodoc_inherit_docstrings = True
autoclass_content = 'both'

View File

@ -1,3 +1,5 @@
# This script generates the source md-files for all classes and functions for the docs
import importlib import importlib
import inspect import inspect
import fnmatch import fnmatch
@ -16,21 +18,21 @@ def write_classes(f: TextIOWrapper, patterns: list[str], module_name: str, title
] ]
"""Write the classes to the file.""" """Write the classes to the file."""
f.write(f'## {title}\n\n')
if description: if description:
f.write(f'{description}\n\n') f.write(f'{description}\n\n')
write_dochtree(f, title, classes)
for cls in classes: for cls in classes:
f.write('```{eval-rst}\n') with open(f'docs/source/_autogenerated/{cls}.md', 'w') as f2:
f.write(f'.. autoclass:: {module_name}.{cls}\n') f2.write(f'# {module_name}.{cls}\n')
f.write(' :members:\n') f2.write('```{eval-rst}\n')
f.write(' :class-doc-from: both\n') f2.write(f'.. autoclass:: {module_name}.{cls}\n')
f.write(' :undoc-members:\n') f2.write(' :members:\n')
f.write(' :show-inheritance:\n') f2.write(' :undoc-members:\n')
f.write(' :inherited-members:\n') f2.write(' :show-inheritance:\n')
if title != 'Base classes': f2.write(' :inherited-members:\n')
f.write(' :exclude-members: select\n') f2.write('```\n\n')
f.write('```\n\n')
def write_functions(f: TextIOWrapper, patterns: list[str], module_name: str, title: str, description: str = '', exclude: list[str] = []) -> None: def write_functions(f: TextIOWrapper, patterns: list[str], module_name: str, title: str, description: str = '', exclude: list[str] = []) -> None:
@ -44,18 +46,36 @@ def write_functions(f: TextIOWrapper, patterns: list[str], module_name: str, tit
] ]
"""Write the classes to the file.""" """Write the classes to the file."""
f.write(f'## {title}\n\n')
if description: if description:
f.write(f'{description}\n\n') f.write(f'{description}\n\n')
write_dochtree(f, title, functions)
for func in functions: for func in functions:
if not func.startswith('_'): if not func.startswith('_'):
f.write('```{eval-rst}\n') with open(f'docs/source/_autogenerated/{func}.md', 'w') as f2:
f.write(f'.. autofunction:: {module_name}.{func}\n') f2.write(f'# {module_name}.{func}\n')
f.write('```\n\n') f2.write('```{eval-rst}\n')
f2.write(f'.. autofunction:: {module_name}.{func}\n')
f2.write('```\n\n')
with open('docs/source/modules.md', 'w') as f: def write_dochtree(f: TextIOWrapper, title: str, items: list[str]):
f.write('# Functions and classes\n\n') f.write('```{toctree}\n')
write_classes(f, ['*'], 'gaspype', title='Classes') f.write(':maxdepth: 1\n')
write_functions(f, ['*'], 'gaspype', title='Functions') f.write(f':caption: {title}:\n')
#f.write(':hidden:\n')
for text in items:
if not text.startswith('_'):
f.write(f"{text}\n")
f.write('```\n\n')
if __name__ == "__main__":
with open('docs/source/_autogenerated/index.md', 'w') as f:
f.write('# Classes and functions\n\n')
#f.write('## Classes\n\n')
write_classes(f, ['*'], 'gaspype', title='Classes')
#f.write('## Functions\n\n')
write_functions(f, ['*'], 'gaspype', title='Functions')

View File

@ -1,9 +1,8 @@
```{toctree} ```{toctree}
:maxdepth: 2 :maxdepth: 1
:caption: Contents: :hidden:
_autogenerated/index
readme _autogenerated/examples
modules
``` ```
```{include} ../../README.md ```{include} ../../README.md