Skip to content

Commit

Permalink
run pre-commit (#158)
Browse files Browse the repository at this point in the history
  • Loading branch information
3nids authored Aug 13, 2024
1 parent 3e1b572 commit 4199c0c
Show file tree
Hide file tree
Showing 6 changed files with 228 additions and 163 deletions.
8 changes: 4 additions & 4 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
repos:
# Fix end of files
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
rev: v4.6.0
hooks:
- id: trailing-whitespace
exclude: .*\.qgs
Expand Down Expand Up @@ -32,21 +32,21 @@ repos:

# Black formatting
- repo: https://github.com/psf/black
rev: "24.3.0"
rev: "24.8.0"
hooks:
- id: black
args: ["--line-length=99"]

# tool to automatically upgrade syntax for newer versions of the language
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.2
rev: v3.17.0
hooks:
- id: pyupgrade
args: [--py311-plus]

# Lint files
- repo: https://github.com/pycqa/flake8
rev: "7.0.0"
rev: "7.1.1"
hooks:
- id: flake8
args: [
Expand Down
51 changes: 34 additions & 17 deletions autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,30 +2,32 @@
# see https://stackoverflow.com/questions/20569011/python-sphinx-autosummary-automated-listing-of-member-functions
# added toctree and nosignatures in options

from enum import Enum
import re
from typing import Any, List, Optional
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.ext import autosummary
from sphinx.util.inspect import safe_getattr
from sphinx.util import logging
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.directives import directive
logger = logging.getLogger(__name__)


old_extract_summary = autosummary.extract_summary


def new_extract_summary(doc: list[str], document: Any) -> str:
res = old_extract_summary(doc, document)
res = re.sub(r'\`((?!(?:None|True|False))[a-zA-Z0-9_]+)\`', r'\1', res)
res = re.sub(r"\`((?!(?:None|True|False))[a-zA-Z0-9_]+)\`", r"\1", res)
return res


autosummary.extract_summary = new_extract_summary


Expand All @@ -46,7 +48,7 @@ class AutoAutoSummary(Autosummary):
"attributes": directives.unchanged,
"nosignatures": directives.unchanged,
"toctree": directives.unchanged,
"exclude-members": directives.unchanged
"exclude-members": directives.unchanged,
}

required_arguments = 1
Expand All @@ -55,18 +57,27 @@ class AutoAutoSummary(Autosummary):
def skip_member(doc, obj: Any, name: str, options, objtype: str) -> bool:
# print(name, name in options.get('exclude-members', '').split(','))
try:
if name in options.get('exclude-members', '').split(','):
if name in options.get("exclude-members", "").split(","):
return True
return doc.settings.env.app.emit_firstresult('autodoc-skip-member', objtype, name,
obj, False, {})
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')
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, options, include_public: Optional[List]=None, signal=False, enum=False):
def get_members(
doc, obj, typ, options, include_public: list | None = None, signal=False, enum=False
):
try:
if not include_public:
include_public = []
Expand All @@ -81,7 +92,9 @@ def get_members(doc, obj, typ, options, include_public: Optional[List]=None, sig
# 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, options, documenter.objtype)
skipped = AutoAutoSummary.skip_member(
doc, chobj, name, options, documenter.objtype
)
if skipped is True:
continue
if typ == "attribute":
Expand Down Expand Up @@ -122,15 +135,19 @@ def run(self):
c = getattr(m, class_name)
if "methods" in self.options:
rubric_title = "Methods"
_, rubric_elems = self.get_members(self.state.document, c, "method", self.options, ["__init__"])
_, rubric_elems = self.get_members(
self.state.document, c, "method", self.options, ["__init__"]
)
elif "enums" in self.options:
rubric_title = "Enums"
_, rubric_elems = self.get_members(
self.state.document, c, "class", self.options, None, False, True
)
elif "signals" in self.options:
rubric_title = "Signals"
_, rubric_elems = self.get_members(self.state.document, c, "attribute", self.options, None, signal=True)
_, rubric_elems = self.get_members(
self.state.document, c, "attribute", self.options, None, signal=True
)
elif "attributes" in self.options:
rubric_title = "Attributes"
_, rubric_elems = self.get_members(
Expand Down
16 changes: 10 additions & 6 deletions conf.in.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@
"sphinxcontrib.jquery",
"sphinx.ext.linkcode",
"inheritance_diagram",
"sphinx.ext.graphviz"

"sphinx.ext.graphviz",
] # , 'rinoh.frontend.sphinx'], 'sphinx_autodoc_typehints'

# The suffix of source filenames.
Expand All @@ -49,7 +48,7 @@
if version == "master":
QGIS_GIT_TAG = "master"
else:
QGIS_GIT_TAG = f"release-{release.replace('.','_')}"
QGIS_GIT_TAG = f"release-{release.replace('.', '_')}"

# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
Expand Down Expand Up @@ -130,7 +129,7 @@
current_ltr = str(cfg["current_ltr"])
version_list = ("master", current_stable, current_ltr)

graphviz_output_format = 'svg'
graphviz_output_format = "svg"

url = cfg["pyqgis_url"]
if not url.endswith("/"):
Expand Down Expand Up @@ -164,7 +163,7 @@

templates_path = ["_templates"]

autodoc_default_options = {'show-inheritance': True}
autodoc_default_options = {"show-inheritance": True}

# If false, no module index is generated.
html_domain_indices = True
Expand Down Expand Up @@ -247,7 +246,12 @@ def linkcode_resolve(domain, info):
def setup(app):
try:
from autoautosummary import AutoAutoSummary
from process_links import process_docstring, process_signature, skip_member, process_bases
from process_links import (
process_bases,
process_docstring,
process_signature,
skip_member,
)

app.add_directive("autoautosummary", AutoAutoSummary)
app.connect("autodoc-process-signature", process_signature)
Expand Down
Loading

0 comments on commit 4199c0c

Please sign in to comment.