Skip to content

Commit 1d447ca

Browse files
committed
Add config to fix or silence most autodoc broken reference warnings
1 parent a0e6177 commit 1d447ca

File tree

2 files changed

+55
-6
lines changed

2 files changed

+55
-6
lines changed

docs/conf.py

Lines changed: 53 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737

3838
# If your documentation needs a minimal Sphinx version, state it here.
3939
#
40-
needs_sphinx = "5"
40+
needs_sphinx = "6.2"
4141

4242
# Add any Sphinx extension module names here, as strings. They can be
4343
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom ones.
@@ -103,9 +103,37 @@
103103
# pylint: disable-next = consider-using-namedtuple-or-dataclass
104104
intersphinx_mapping = {
105105
"python": ("https://docs.python.org/", None),
106+
"PyQt5": ("https://www.riverbankcomputing.com/static/Docs/PyQt5/", None),
106107
"spyder": ("https://docs.spyder-ide.org/current/", None),
107108
}
108109

110+
# Warning suppression
111+
suppress_warnings = []
112+
113+
# Nitpick warning ignore list
114+
nitpick_ignore_regex = {
115+
# Spyder modules currently not included in the build
116+
(
117+
"py:.+",
118+
# pylint: disable-next = line-too-long
119+
"spyder.(app|config|fonts|images|locale|plugins|tests|utils|widgets|windows).*", # noqa: E501
120+
),
121+
# Numpydoc optional
122+
("py:class", "optional"),
123+
# Typing params
124+
("py:.+", ".*_P"),
125+
("py:.+", ".*_RT"),
126+
("py:.+", ".*_T"),
127+
# Cannot use type aliases to fix refs inside type aliases or class bases
128+
("py:class", "asyncio.events.AbstractEventLoop"),
129+
("py:class", "concurrent.futures._base.Future"),
130+
# Type aliases don't work properly in Sphinx <9
131+
("py:class", "LoopID"),
132+
("py:class", "OptionSet"),
133+
("py:class", "spyder.api.preferences.OptionSet"),
134+
}
135+
136+
109137
# -- Options for HTML output -------------------------------------------
110138

111139
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -135,9 +163,6 @@
135163
# so a file named "default.css" will overwrite the builtin "default.css".
136164
html_static_path = ["_static"]
137165

138-
# Warning suppression
139-
suppress_warnings = []
140-
141166

142167
# -- Options for HTMLHelp output ---------------------------------------
143168

@@ -260,6 +285,28 @@
260285
# "qstylizer",
261286
]
262287

288+
# Configure type aliases for signatures
289+
autodoc_type_aliases = {
290+
# Actual type aliases
291+
"LoopID": "spyder.api.asyncdispatcher.LoopID",
292+
"OptionSet": "spyder.api.preferences.OptionSet",
293+
# Ref name aliases
294+
"AbstractEventLoop": "asyncio.AbstractEventLoop",
295+
"asyncio.AbstractEventLoop": "asyncio.AbstractEventLoop",
296+
"asyncio.events.AbstractEventLoop": "asyncio.AbstractEventLoop",
297+
"Future": "concurrent.futures.Future",
298+
"concurrent.futures.Future": "concurrent.futures.Future",
299+
"concurrent.futures._base.Future": "concurrent.futures.Future",
300+
}
301+
302+
# Monkeypatch to fix type aliases not working in classmethods with Sphinx
303+
# See sphinx-doc/sphinx#10333
304+
# pylint: disable-next = wrong-import-position
305+
from sphinx.util import inspect # noqa: E402
306+
307+
inspect.TypeAliasForwardRef.__repr__ = lambda self: self.name
308+
inspect.TypeAliasForwardRef.__hash__ = lambda self: hash(self.name)
309+
263310
# Set list of modules and patterns to ignore in the autosummary template
264311
autosummary_context = {
265312
"ignore_module_pattern": "tests",
@@ -276,10 +323,11 @@
276323
if "autodoc" in tags: # noqa: F821
277324
autosummary_generate = True
278325
os.environ["SPHINX_AUTODOC"] = "1"
326+
extensions.append("sphinx_qt_documentation") # Errors out w/o Qt installed
279327
else:
280328
autosummary_generate = False
281-
suppress_warnings += ["autodoc", "autosummary", "toc.excluded"]
282329
exclude_patterns += ["reference.rst"]
330+
suppress_warnings += ["autodoc", "autosummary", "toc.excluded"]
283331

284332

285333
# -- Additional Directives ---------------------------------------------------

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
myst-parser>=1,<5 # Docs markup; cap to support wide range of py versions
2-
sphinx>=5,<9 # Docs generator; cap to range confirmed supported by deps
2+
sphinx>=6.2,<9 # Docs generator; cap to range confirmed supported by deps
33
sphinx-book-theme>=1,<2 # Docs theme; cap to support wide range of py versions
4+
sphinx-qt-documentation>=0.4.1,<1 # Crossrefs to Qt documentation

0 commit comments

Comments
 (0)