-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #162 from h2020charisma/docs-decorated
docs: add decorated functions list
- Loading branch information
Showing
4 changed files
with
51 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -83,6 +83,7 @@ instance/ | |
|
||
# Sphinx documentation | ||
docs/_build/ | ||
spectrum_functions.md | ||
|
||
# PyBuilder | ||
.pybuilder/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters