Skip to content

Commit

Permalink
Silence a noisy warning when building docs (#169)
Browse files Browse the repository at this point in the history
autosummary fails to import class attributes exposed by sip,
which results in thousands of warnings dumped during the doc
build.

Hack around this, so that we only get valid warnings when
building docs
  • Loading branch information
nyalldawson authored Aug 27, 2024
1 parent 22be803 commit 1c0c03f
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion autoautosummary.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from docutils import nodes
from docutils.parsers.rst import directives
from sphinx.ext import autosummary
from sphinx.ext.autosummary import Autosummary, get_documenter
from sphinx.ext.autosummary import Autosummary, ImportExceptionGroup, get_documenter
from sphinx.locale import __
from sphinx.util import logging
from sphinx.util.inspect import isstaticmethod, safe_getattr
Expand Down Expand Up @@ -140,6 +140,28 @@ def get_members(
print(str(e))
raise e

def import_by_name(
self,
name: str,
prefixes: list[str | None],
) -> tuple[str, Any, Any, str]:
"""
We have to wrap the original import_by_name, which raises noisy
exceptions when trying to handle class attributes exposed by SIP.
"""
try:
res = super().import_by_name(name, prefixes)
except ImportExceptionGroup:
# class attribute import failed, just handle this by faking
# the results. The resultant documentation still correctly
# contains the attribute docstrings...
name_parts = name.split(".")
parent_name = ".".join(name_parts[:-1])
parent_res = super().import_by_name(parent_name, prefixes)
res = (name, None, parent_res[2], parent_res[3])

return res

def run(self):
clazz = self.arguments[0]
rubric_title = None
Expand Down

0 comments on commit 1c0c03f

Please sign in to comment.