Skip to content

Commit

Permalink
[pre-commit.ci] auto fixes from pre-commit.com hooks
Browse files Browse the repository at this point in the history
for more information, see https://pre-commit.ci
  • Loading branch information
pre-commit-ci[bot] committed Apr 20, 2023
1 parent 5b2f9de commit 14dae84
Showing 1 changed file with 20 additions and 17 deletions.
37 changes: 20 additions & 17 deletions docs/_ext/hack_autosummary.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from types import FunctionType
from inspect import signature
from types import FunctionType

from sphinx.ext.autosummary.generate import generate_autosummary_content

GENERATE_SIGNATURE = signature(generate_autosummary_content)
Expand All @@ -22,13 +23,13 @@ def subclasses(obj, seen=None):

def hack_autosummary_content(*args, **kwargs):
ba = GENERATE_SIGNATURE.bind_partial(*args, **kwargs)
name = ba.arguments['name']
parent = ba.arguments['parent']
context = ba.arguments['context']
*_, name = name.rpartition('.')
context['subclasses'] = [cls.__name__
for cls in subclasses(parent)
if hasattr(cls, name)]
name = ba.arguments["name"]
parent = ba.arguments["parent"]
context = ba.arguments["context"]
*_, name = name.rpartition(".")
context["subclasses"] = [
cls.__name__ for cls in subclasses(parent) if hasattr(cls, name)
]
return generate_autosummary_content(*args, **kwargs)


Expand All @@ -38,18 +39,20 @@ def setup(app):
original = sphinx.ext.autosummary.generate.generate_autosummary_docs

hacked_globals = original.__globals__.copy()
hacked_globals['generate_autosummary_content'] = hack_autosummary_content
hacked_globals["generate_autosummary_content"] = hack_autosummary_content

hacked = FunctionType(code=original.__code__,
globals=hacked_globals,
name=original.__name__,
argdefs=original.__defaults__,
closure=original.__closure__)
hacked = FunctionType(
code=original.__code__,
globals=hacked_globals,
name=original.__name__,
argdefs=original.__defaults__,
closure=original.__closure__,
)

sphinx.ext.autosummary.generate.generate_autosummary_docs = hacked

return {
'version': '0.1',
'parallel_read_safe': True,
'parallel_write_safe': True,
"version": "0.1",
"parallel_read_safe": True,
"parallel_write_safe": True,
}

0 comments on commit 14dae84

Please sign in to comment.