Skip to content
Snippets Groups Projects
Commit 0f5854b3 authored by Cyril Moineau's avatar Cyril Moineau
Browse files

Add template_docstring decorator which allow to template Python docstring.

parent c3b322c5
No related branches found
No related tags found
No related merge requests found
...@@ -9,3 +9,4 @@ SPDX-License-Identifier: EPL-2.0 ...@@ -9,3 +9,4 @@ SPDX-License-Identifier: EPL-2.0
""" """
from aidge_core.aidge_core import * # import so generated by PyBind from aidge_core.aidge_core import * # import so generated by PyBind
from aidge_core.export import ExportNode from aidge_core.export import ExportNode
import aidge_core.utils
def template_docstring(template_keyword, text_to_replace):
"""Method to template docstring
:param template: Template keyword to replace, in the documentation you template word must be between `{` `}`
:type template: str
:param text_to_replace: Text to replace your template with.
:type text_to_replace: str
"""
def dec(func):
if "{"+template_keyword+"}" not in func.__doc__:
raise RuntimeError(
f"The function {function.__name__} docstring does not contain the template keyword: {template_keyword}.")
func.__doc__ = func.__doc__.replace(
"{"+template_keyword+"}", text_to_replace)
return func
return dec
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment