From d4dfa4c97d37e08285224a50133625c969170a26 Mon Sep 17 00:00:00 2001 From: Luchesar ILIEV Date: Tue, 17 Sep 2024 18:22:46 +0300 Subject: [PATCH 1/2] docs: add decorated functions list --- .gitignore | 1 + scripts/gen-decorated-docs.py | 33 +++++++++++++++++++++++++++++++++ src/ramanchada2/__init__.py | 2 ++ tox.ini | 17 ++++++++++++++--- 4 files changed, 50 insertions(+), 3 deletions(-) create mode 100644 scripts/gen-decorated-docs.py diff --git a/.gitignore b/.gitignore index e8f94558..b93c8e53 100644 --- a/.gitignore +++ b/.gitignore @@ -83,6 +83,7 @@ instance/ # Sphinx documentation docs/_build/ +spectrum_functions.md # PyBuilder .pybuilder/ diff --git a/scripts/gen-decorated-docs.py b/scripts/gen-decorated-docs.py new file mode 100644 index 00000000..ba5c16cf --- /dev/null +++ b/scripts/gen-decorated-docs.py @@ -0,0 +1,33 @@ +import inspect + +import ramanchada2 as rc2 + + +# Get all methods or functions with decorators +def get_decorated_functions(cls): + decorated_functions = [] + for name, method in inspect.getmembers(cls, predicate=inspect.isfunction): + + if hasattr(method, "__wrapped__"): + + doc = method.__doc__ # Get the docstring (None if not available) + decorated_functions.append((name, "" if doc is None else doc)) + return decorated_functions + + +def generate_decorated_function_docs_markdown(cls, filename="spectrum_functions.md"): + """ + Generates a markdown file that lists decorated functions and their docstrings. + """ + with open(filename, "w") as f: + f.write(f"# Decorated Functions in {cls.__name__}\n\n") + + decorated_funcs_with_docs = get_decorated_functions(cls) + + for func_name, doc in decorated_funcs_with_docs: + f.write(f"### Function: `{func_name}`\n\n") + f.write(f"**Docstring:** {doc if doc else 'No docstring available'}\n\n") + f.write("---\n\n") + + +generate_decorated_function_docs_markdown(rc2.spectrum.Spectrum) diff --git a/src/ramanchada2/__init__.py b/src/ramanchada2/__init__.py index 0b427bf8..eecb76ce 100644 --- a/src/ramanchada2/__init__.py +++ b/src/ramanchada2/__init__.py @@ -82,6 +82,8 @@ [h5pyd]: https://github.com/HDFGroup/h5pyd [ramanchada]: https://github.com/h2020charisma/ramanchada [NeXus]: https://www.nexusformat.org/ + +.. include:: ../../../../../../spectrum_functions.md """ from __future__ import annotations diff --git a/tox.ini b/tox.ini index 9cd3c1b2..cb9713cd 100644 --- a/tox.ini +++ b/tox.ini @@ -1,11 +1,11 @@ [tox] -env_list = clean, py311, mypy, flake8, docs +env_list = clean, py311, mypy, black, usort, flake8, docs [gh-actions] python = 3.9: py39 3.10: py310 - 3.11: py311, mypy, flake8, docs + 3.11: py311, mypy, black, usort, flake8, docs 3.12: py312 [flake8] @@ -42,15 +42,26 @@ base_python = python3.11 deps = mypy commands = mypy src tests +[testenv:black] +base_python = python3.11 +deps=black +commands = black scripts + +[testenv:usort] +base_python = python3.11 +deps=usort +commands = usort format scripts + [testenv:flake8] base_python = python3.11 deps = flake8 -commands = flake8 src tests +commands = flake8 scripts src tests [testenv:docs] base_python = python3.11 deps = pdoc commands = + python scripts/gen-decorated-docs.py pdoc ramanchada2 -o {toxinidir}/docs/_build --no-browser --search --math --docformat google --show-source [testenv:ipynb] From b71e7c04586c1bb2dd9d6b7fb66a63f0b7e6ebeb Mon Sep 17 00:00:00 2001 From: Luchesar ILIEV Date: Tue, 17 Sep 2024 18:25:36 +0300 Subject: [PATCH 2/2] docs: remove default pdoc options --- tox.ini | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tox.ini b/tox.ini index cb9713cd..9c25d0cd 100644 --- a/tox.ini +++ b/tox.ini @@ -62,7 +62,7 @@ base_python = python3.11 deps = pdoc commands = python scripts/gen-decorated-docs.py - pdoc ramanchada2 -o {toxinidir}/docs/_build --no-browser --search --math --docformat google --show-source + pdoc ramanchada2 -o {toxinidir}/docs/_build --math --docformat google [testenv:ipynb] deps = jupyter