From 05d14397eb9e165a85e0d58c11c6cc8b19ba1113 Mon Sep 17 00:00:00 2001 From: AnonymouX47 Date: Thu, 26 Sep 2024 23:50:05 +0100 Subject: [PATCH] docs: Improve decorator function autodocumentation - Add: `sphinx_toolbox.decorators` sphinx extension. - Change: Patch `autodecorator` directive. Decorator functions at module are now automatically detected by the `automodule` directive. --- docs/source/conf.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/source/conf.py b/docs/source/conf.py index 6598b05d..4b7847c7 100644 --- a/docs/source/conf.py +++ b/docs/source/conf.py @@ -3,6 +3,7 @@ # For the full list of configuration options, see the documentation: # https://www.sphinx-doc.org/en/master/usage/configuration.html +from sphinx.ext.autodoc import DecoratorDocumenter, FunctionDocumenter from sphinx_toolbox.collapse import CollapseNode from sphinxcontrib import prettyspecialmethods @@ -29,6 +30,7 @@ "sphinx.ext.napoleon", "sphinx.ext.viewcode", "sphinx.ext.intersphinx", + "sphinx_toolbox.decorators", "sphinx_toolbox.github", "sphinx_toolbox.sidebar_links", "sphinx_toolbox.more_autosummary", @@ -144,6 +146,19 @@ def autodocssumm_grouper(app, what, name, obj, section, parent): if isinstance(value, utils.ClassPropertyBase): delattr(meta, attr) +# # -- autodecorator ------------------------------------------------------------- + + +@classmethod +def can_document_member(cls, member, *args, **kwargs): + return hasattr(member, "_no_redecorate_wrapped_") and ( + super(DecoratorDocumenter, cls).can_document_member(member, *args, **kwargs) + ) + + +DecoratorDocumenter.priority = FunctionDocumenter.priority + 5 +DecoratorDocumenter.can_document_member = can_document_member + # # -- prettyspecialmethods ------------------------------------------------------