Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add decorated functions list #162

Merged
merged 2 commits into from
Sep 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ instance/

# Sphinx documentation
docs/_build/
spectrum_functions.md

# PyBuilder
.pybuilder/
Expand Down
33 changes: 33 additions & 0 deletions scripts/gen-decorated-docs.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions src/ramanchada2/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
19 changes: 15 additions & 4 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -42,16 +42,27 @@ 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 =
pdoc ramanchada2 -o {toxinidir}/docs/_build --no-browser --search --math --docformat google --show-source
python scripts/gen-decorated-docs.py
pdoc ramanchada2 -o {toxinidir}/docs/_build --math --docformat google

[testenv:ipynb]
deps = jupyter
Expand Down
Loading