diff --git a/autoautosummary.py b/autoautosummary.py index 0bfda22ed502..46006f8efe6b 100644 --- a/autoautosummary.py +++ b/autoautosummary.py @@ -13,7 +13,7 @@ from sphinx.ext.autosummary import Autosummary, get_documenter from sphinx.locale import __ from sphinx.util import logging -from sphinx.util.inspect import safe_getattr +from sphinx.util.inspect import safe_getattr, isstaticmethod # from sphinx.directives import directive logger = logging.getLogger(__name__) @@ -43,6 +43,7 @@ class AutoAutoSummary(Autosummary): option_spec = { "methods": directives.unchanged, + "static_methods": directives.unchanged, "signals": directives.unchanged, "enums": directives.unchanged, "attributes": directives.unchanged, @@ -76,7 +77,7 @@ def skip_member(doc, obj: Any, name: str, options, objtype: str) -> bool: @staticmethod def get_members( - doc, obj, typ, options, include_public: list | None = None, signal=False, enum=False + doc, obj, typ, options, include_public: list | None = None, signal=False, enum=False, static=False ): try: if not include_public: @@ -97,7 +98,11 @@ def get_members( ) if skipped is True: continue - if typ == "attribute": + if typ == "method": + method_is_static = isstaticmethod(chobj, obj, name) + if method_is_static != static: + continue + elif typ == "attribute": if signal and not isinstance(chobj, PyQt5.QtCore.pyqtSignal): continue if not signal and isinstance(chobj, PyQt5.QtCore.pyqtSignal): @@ -138,6 +143,12 @@ def run(self): _, rubric_elems = self.get_members( self.state.document, c, "method", self.options, ["__init__"] ) + elif "static_methods" in self.options: + rubric_title = "Static Methods" + _, rubric_elems = self.get_members(self.state.document, c, + "method", + self.options, + static=True) elif "enums" in self.options: rubric_title = "Enums" _, rubric_elems = self.get_members( diff --git a/rst/qgis_pydoc_template.txt b/rst/qgis_pydoc_template.txt index 08ca17e71f96..e5606ff36736 100644 --- a/rst/qgis_pydoc_template.txt +++ b/rst/qgis_pydoc_template.txt @@ -24,6 +24,11 @@ Class: $CLASS :nosignatures: :exclude-members: $EXCLUDE_METHODS + .. autoautosummary:: qgis.$PACKAGE.$CLASS + :static_methods: + :nosignatures: + :exclude-members: $EXCLUDE_METHODS + .. autoautosummary:: qgis.$PACKAGE.$CLASS :signals: :nosignatures: