Skip to content

Commit

Permalink
Split static methods to own section in autosummary
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Aug 14, 2024
1 parent 4199c0c commit 7a7ba4f
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
17 changes: 14 additions & 3 deletions autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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:
Expand All @@ -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):
Expand Down Expand Up @@ -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(
Expand Down
5 changes: 5 additions & 0 deletions rst/qgis_pydoc_template.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 7a7ba4f

Please sign in to comment.