diff --git a/aidge_core/__init__.py b/aidge_core/__init__.py index c65dcc6cfc4be8825d1213854014718fb7170854..5f4e8367200d9fb28b7ec0fc817e5ad177b30c8d 100644 --- a/aidge_core/__init__.py +++ b/aidge_core/__init__.py @@ -9,3 +9,4 @@ SPDX-License-Identifier: EPL-2.0 """ from aidge_core.aidge_core import * # import so generated by PyBind from aidge_core.export import ExportNode +import aidge_core.utils diff --git a/aidge_core/utils.py b/aidge_core/utils.py new file mode 100644 index 0000000000000000000000000000000000000000..d82d524b7e886ed396507376a5934a748a89e44c --- /dev/null +++ b/aidge_core/utils.py @@ -0,0 +1,16 @@ +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