Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure that skipped methods are skipped in autosummary too #151

Merged
merged 3 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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:
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion process_links.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down
8 changes: 7 additions & 1 deletion scripts/make_api_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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)
Expand Down