From 30eff86a738152befbcae47d7c8afda4ab656403 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 6 Aug 2024 11:47:54 +1000 Subject: [PATCH 1/3] Skip skipped in toc --- autoautosummary.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/autoautosummary.py b/autoautosummary.py index f34581df5d2e..d614ec37bdfe 100644 --- a/autoautosummary.py +++ b/autoautosummary.py @@ -3,14 +3,18 @@ # added toctree and nosignatures in options from enum import Enum +from typing import Any import PyQt5 from docutils import nodes from docutils.parsers.rst import directives from sphinx.ext.autosummary import Autosummary, get_documenter from sphinx.util.inspect import safe_getattr +from sphinx.util import logging +from sphinx.locale import __ # from sphinx.directives import directive +logger = logging.getLogger(__name__) class AutoAutoSummary(Autosummary): @@ -34,6 +38,17 @@ class AutoAutoSummary(Autosummary): required_arguments = 1 + @staticmethod + def skip_member(doc, obj: Any, name: str, objtype: str) -> bool: + try: + return doc.settings.env.app.emit_firstresult('autodoc-skip-member', objtype, name, + obj, False, {}) + except Exception as exc: + logger.warning(__('autosummary: failed to determine %r to be documented.' + 'the following exception was raised:\n%s'), + name, exc, type='autosummary') + return False + @staticmethod def get_members(doc, obj, typ, include_public=None, signal=False, enum=False): try: @@ -50,6 +65,9 @@ def get_members(doc, obj, typ, include_public=None, signal=False, enum=False): # cl = get_class_that_defined_method(chobj) # print(name, chobj.__qualname__, type(chobj), issubclass(chobj, Enum), documenter.objtype) if documenter.objtype == typ: + skipped = AutoAutoSummary.skip_member(doc, chobj, name, documenter.objtype) + if skipped is True: + continue if typ == "attribute": if signal and isinstance(chobj, PyQt5.QtCore.pyqtSignal): continue From a06ad14825c9aa05125b3ea9d1a320f44a010a7a Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 6 Aug 2024 12:08:38 +1000 Subject: [PATCH 2/3] Exclude 'baseClass' from enum class documentation Fixes #78 --- process_links.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/process_links.py b/process_links.py index 7f9ac68ccc89..b84abd905d78 100644 --- a/process_links.py +++ b/process_links.py @@ -129,6 +129,8 @@ def skip_member(app, what, name, obj, skip, options): # skip monkey patched enums (base classes are different) if name == "staticMetaObject": return True + if name == "baseClass": + return True if hasattr(obj, "is_monkey_patched") and obj.is_monkey_patched: print(f"skipping monkey patched enum {name}") return True From 2a3add2c5b78108fc4f75bbc6cc100c139391b32 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Tue, 6 Aug 2024 15:18:24 +1000 Subject: [PATCH 3/3] Skip some alias classes Eg enums from Qgis should not be listed in the class list --- process_links.py | 2 +- scripts/make_api_rst.py | 8 +++++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/process_links.py b/process_links.py index b84abd905d78..5df12931e4c2 100644 --- a/process_links.py +++ b/process_links.py @@ -72,7 +72,7 @@ def process_docstring(app, what, name, obj, options, lines): if signature != "": match = py_ext_sig_re.match(signature) if not match: - print(obj) + # print(obj) if name not in cfg["non-instantiable"]: raise Warning(f"invalid signature for {name}: {signature}") else: diff --git a/scripts/make_api_rst.py b/scripts/make_api_rst.py index 70575cb486d2..7df1a0e9161e 100755 --- a/scripts/make_api_rst.py +++ b/scripts/make_api_rst.py @@ -183,7 +183,7 @@ def generate_docs(): package_index.write(package_header.replace("PACKAGENAME", package_name)) for class_name in extract_package_classes(package): - print(class_name) + # print(class_name) substitutions = {"PACKAGE": package_name, "CLASS": class_name} class_template = template.substitute(**substitutions) class_rst = open(f"api/{qgis_version}/{package_name}/{class_name}.rst", "w") @@ -220,6 +220,12 @@ def extract_package_classes(package): continue if class_name in cfg["skipped"]: continue + + _class = getattr(package, class_name) + if hasattr(_class, '__name__') and class_name != _class.__name__: + print(f'Skipping alias {class_name}, {_class.__name__}') + continue + # if not re.match('^Qgi?s', class_name): # continue classes.append(class_name)