mirror of https://github.com/Nonannet/copapy.git
sphinx based docs added
This commit is contained in:
parent
bf1c3468b3
commit
2cb5499299
|
|
@ -21,3 +21,5 @@ build/*
|
||||||
/src/*.pyd
|
/src/*.pyd
|
||||||
vc140.pdb
|
vc140.pdb
|
||||||
benchmark_results*
|
benchmark_results*
|
||||||
|
docs/build
|
||||||
|
docs/source/api
|
||||||
|
|
@ -0,0 +1,20 @@
|
||||||
|
# Minimal makefile for Sphinx documentation
|
||||||
|
#
|
||||||
|
|
||||||
|
# You can set these variables from the command line, and also
|
||||||
|
# from the environment for the first two.
|
||||||
|
SPHINXOPTS ?=
|
||||||
|
SPHINXBUILD ?= sphinx-build
|
||||||
|
SOURCEDIR = source
|
||||||
|
BUILDDIR = build
|
||||||
|
|
||||||
|
# Put it first so that "make" without argument is like "make help".
|
||||||
|
help:
|
||||||
|
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
||||||
|
.PHONY: help Makefile
|
||||||
|
|
||||||
|
# Catch-all target: route all unknown targets to Sphinx using the new
|
||||||
|
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
|
||||||
|
%: Makefile
|
||||||
|
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
|
||||||
|
|
@ -0,0 +1,35 @@
|
||||||
|
@ECHO OFF
|
||||||
|
|
||||||
|
pushd %~dp0
|
||||||
|
|
||||||
|
REM Command file for Sphinx documentation
|
||||||
|
|
||||||
|
if "%SPHINXBUILD%" == "" (
|
||||||
|
set SPHINXBUILD=sphinx-build
|
||||||
|
)
|
||||||
|
set SOURCEDIR=source
|
||||||
|
set BUILDDIR=build
|
||||||
|
|
||||||
|
%SPHINXBUILD% >NUL 2>NUL
|
||||||
|
if errorlevel 9009 (
|
||||||
|
echo.
|
||||||
|
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
|
||||||
|
echo.installed, then set the SPHINXBUILD environment variable to point
|
||||||
|
echo.to the full path of the 'sphinx-build' executable. Alternatively you
|
||||||
|
echo.may add the Sphinx directory to PATH.
|
||||||
|
echo.
|
||||||
|
echo.If you don't have Sphinx installed, grab it from
|
||||||
|
echo.https://www.sphinx-doc.org/
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
|
||||||
|
if "%1" == "" goto help
|
||||||
|
|
||||||
|
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
goto end
|
||||||
|
|
||||||
|
:help
|
||||||
|
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
|
||||||
|
|
||||||
|
:end
|
||||||
|
popd
|
||||||
|
|
@ -0,0 +1,37 @@
|
||||||
|
# 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 os
|
||||||
|
import sys
|
||||||
|
sys.path.insert(0, os.path.abspath("../src/"))
|
||||||
|
|
||||||
|
project = 'copapy'
|
||||||
|
copyright = '2025, Nicolas Kruse'
|
||||||
|
author = 'Nicolas Kruse'
|
||||||
|
|
||||||
|
# -- 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"]
|
||||||
|
|
||||||
|
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_theme = 'pydata_sphinx_theme'
|
||||||
|
html_static_path = ['_static']
|
||||||
|
html_theme_options = {
|
||||||
|
"secondary_sidebar_items": ["page-toc"],
|
||||||
|
"footer_start": ["copyright"]
|
||||||
|
}
|
||||||
|
html_theme_options["footer_end"] = []
|
||||||
|
|
||||||
|
autodoc_inherit_docstrings = True
|
||||||
|
|
@ -0,0 +1,86 @@
|
||||||
|
# This script generates the source md-files for all classes and functions for the docs
|
||||||
|
|
||||||
|
import importlib
|
||||||
|
import inspect
|
||||||
|
import fnmatch
|
||||||
|
from io import TextIOWrapper
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
def write_manual(f: TextIOWrapper, doc_files: list[str], title: str) -> None:
|
||||||
|
write_dochtree(f, title, doc_files)
|
||||||
|
|
||||||
|
|
||||||
|
def write_classes(f: TextIOWrapper, patterns: list[str], module_name: str, title: str, description: str = '', exclude: list[str] = []) -> None:
|
||||||
|
"""Write the classes to the file."""
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
|
||||||
|
classes = [
|
||||||
|
name for name, obj in inspect.getmembers(module, inspect.isclass)
|
||||||
|
if (any(fnmatch.fnmatch(name, pat) for pat in patterns if pat not in exclude) and
|
||||||
|
obj.__doc__ and '(Automatic generated stub)' not in obj.__doc__)
|
||||||
|
]
|
||||||
|
|
||||||
|
if description:
|
||||||
|
f.write(f'{description}\n\n')
|
||||||
|
|
||||||
|
write_dochtree(f, title, classes)
|
||||||
|
|
||||||
|
for cls in classes:
|
||||||
|
with open(f'docs/source/api/{cls}.md', 'w') as f2:
|
||||||
|
f2.write(f'# {module_name}.{cls}\n')
|
||||||
|
f2.write('```{eval-rst}\n')
|
||||||
|
f2.write(f'.. autoclass:: {module_name}.{cls}\n')
|
||||||
|
f2.write(' :members:\n')
|
||||||
|
f2.write(' :undoc-members:\n')
|
||||||
|
f2.write(' :show-inheritance:\n')
|
||||||
|
f2.write(' :inherited-members:\n')
|
||||||
|
f2.write('```\n\n')
|
||||||
|
|
||||||
|
|
||||||
|
def write_functions(f: TextIOWrapper, patterns: list[str], module_name: str, title: str, description: str = '', exclude: list[str] = []) -> None:
|
||||||
|
"""Write the classes to the file."""
|
||||||
|
module = importlib.import_module(module_name)
|
||||||
|
|
||||||
|
functions = [
|
||||||
|
name for name, _ in inspect.getmembers(module, inspect.isfunction)
|
||||||
|
if (any(fnmatch.fnmatch(name, pat) for pat in patterns if pat not in exclude))
|
||||||
|
]
|
||||||
|
|
||||||
|
if description:
|
||||||
|
f.write(f'{description}\n\n')
|
||||||
|
|
||||||
|
write_dochtree(f, title, functions)
|
||||||
|
|
||||||
|
for func in functions:
|
||||||
|
if not func.startswith('_'):
|
||||||
|
with open(f'docs/source/api/{func}.md', 'w') as f2:
|
||||||
|
f2.write(f'# {module_name}.{func}\n')
|
||||||
|
f2.write('```{eval-rst}\n')
|
||||||
|
f2.write(f'.. autofunction:: {module_name}.{func}\n')
|
||||||
|
f2.write('```\n\n')
|
||||||
|
|
||||||
|
|
||||||
|
def write_dochtree(f: TextIOWrapper, title: str, items: list[str]):
|
||||||
|
f.write('```{toctree}\n')
|
||||||
|
f.write(':maxdepth: 1\n')
|
||||||
|
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__":
|
||||||
|
# Ensure the output directory exists
|
||||||
|
os.makedirs('docs/source/api', exist_ok=True)
|
||||||
|
|
||||||
|
with open('docs/source/api/index.md', 'w') as f:
|
||||||
|
f.write('# Classes and functions\n\n')
|
||||||
|
|
||||||
|
write_classes(f, ['*'], 'copapy', title='Classes')
|
||||||
|
|
||||||
|
write_functions(f, ['*'], 'copapy', title='Functions')
|
||||||
|
|
||||||
|
#write_manual(f, ['../ndfloat', '../floatarray'], title='Types')
|
||||||
|
|
@ -0,0 +1,9 @@
|
||||||
|
```{toctree}
|
||||||
|
:maxdepth: 1
|
||||||
|
:hidden:
|
||||||
|
api/index
|
||||||
|
repo
|
||||||
|
```
|
||||||
|
|
||||||
|
```{include} ../../README.md
|
||||||
|
```
|
||||||
|
|
@ -0,0 +1,3 @@
|
||||||
|
# Code repository
|
||||||
|
|
||||||
|
Code repository is on GitHub: [github.com/Nonannet/copapy](https://github.com/Nonannet/copapy).
|
||||||
|
|
@ -36,6 +36,12 @@ dev = [
|
||||||
"mypy",
|
"mypy",
|
||||||
"pytest"
|
"pytest"
|
||||||
]
|
]
|
||||||
|
doc_build = [
|
||||||
|
"sphinx",
|
||||||
|
"pydata_sphinx_theme",
|
||||||
|
"sphinx-autodoc-typehints",
|
||||||
|
"myst-parser"
|
||||||
|
]
|
||||||
|
|
||||||
[tool.mypy]
|
[tool.mypy]
|
||||||
files = ["src", "tools", "stencils"]
|
files = ["src", "tools", "stencils"]
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue