From 7a7ba4faba06e4090e9502380c0739397b6c0cd7 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Wed, 14 Aug 2024 16:46:32 +1000 Subject: [PATCH 1/2] Split static methods to own section in autosummary --- autoautosummary.py | 17 ++++++++++++++--- rst/qgis_pydoc_template.txt | 5 +++++ 2 files changed, 19 insertions(+), 3 deletions(-) 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: From 41d606b4b217a4ffcadd996cbe6a1889e132560f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 14 Aug 2024 06:53:27 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- autoautosummary.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/autoautosummary.py b/autoautosummary.py index 46006f8efe6b..855f6bc2f3ed 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, isstaticmethod +from sphinx.util.inspect import isstaticmethod, safe_getattr # from sphinx.directives import directive logger = logging.getLogger(__name__) @@ -77,7 +77,14 @@ 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, static=False + doc, + obj, + typ, + options, + include_public: list | None = None, + signal=False, + enum=False, + static=False, ): try: if not include_public: @@ -145,10 +152,9 @@ def run(self): ) elif "static_methods" in self.options: rubric_title = "Static Methods" - _, rubric_elems = self.get_members(self.state.document, c, - "method", - self.options, - static=True) + _, 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(