Skip to content

Commit 9244a4d

Browse files
authored
Merge pull request spyder-ide#14 from CAM-Gerlach/revise-top-level-docstrings
Revise docstrings for modules, fix ref errors, hide private modules & add env var
2 parents 7a3ae02 + 1d447ca commit 9244a4d

File tree

4 files changed

+74
-8
lines changed

4 files changed

+74
-8
lines changed

docs/_templates/custom-module-template.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@
5555
:template: custom-module-template.rst
5656
:recursive:
5757
{% for item in modules %}
58-
{% if not 'tests' in item %}
58+
{%- set item_fullname %}{{ fullname }}.{{ item }}{% endset %}
59+
{%- if not (ignore_module_pattern in item or item_fullname in ignore_modules) %}
5960
{{ item }}
6061
{%- endif %}
6162
{%- endfor %}

docs/conf.py

Lines changed: 69 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
# Standard library imports
1919
import datetime
20+
import os
2021
import sys
2122
from pathlib import Path
2223

@@ -36,7 +37,7 @@
3637

3738
# If your documentation needs a minimal Sphinx version, state it here.
3839
#
39-
needs_sphinx = "5"
40+
needs_sphinx = "6.2"
4041

4142
# Add any Sphinx extension module names here, as strings. They can be
4243
# extensions coming with Sphinx (named "sphinx.ext.*") or your custom ones.
@@ -102,9 +103,37 @@
102103
# pylint: disable-next = consider-using-namedtuple-or-dataclass
103104
intersphinx_mapping = {
104105
"python": ("https://docs.python.org/", None),
106+
"PyQt5": ("https://www.riverbankcomputing.com/static/Docs/PyQt5/", None),
105107
"spyder": ("https://docs.spyder-ide.org/current/", None),
106108
}
107109

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+
108137
# -- Options for HTML output -------------------------------------------
109138

110139
# The theme to use for HTML and HTML Help pages. See the documentation for
@@ -134,9 +163,6 @@
134163
# so a file named "default.css" will overwrite the builtin "default.css".
135164
html_static_path = ["_static"]
136165

137-
# Warning suppression
138-
suppress_warnings = []
139-
140166

141167
# -- Options for HTMLHelp output ---------------------------------------
142168

@@ -246,6 +272,9 @@
246272
# Default flags used by autodoc directives
247273
autodoc_default_options = {
248274
"members": True,
275+
"private-members": "_",
276+
"special-members": True,
277+
"exclude-members": "__weakref__",
249278
"show-inheritance": True,
250279
}
251280

@@ -256,14 +285,49 @@
256285
# "qstylizer",
257286
]
258287

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+
310+
# Set list of modules and patterns to ignore in the autosummary template
311+
autosummary_context = {
312+
"ignore_module_pattern": "tests",
313+
"ignore_modules": [
314+
"spyder.api.editor",
315+
"spyder.api.plugins.enum",
316+
"spyder.api.plugins.new_api",
317+
"spyder.api.plugins.tests",
318+
],
319+
}
320+
259321
# Generate autosummaries if the autodoc tag is passed
260322
# pylint: disable-next = undefined-variable
261323
if "autodoc" in tags: # noqa: F821
262324
autosummary_generate = True
325+
os.environ["SPHINX_AUTODOC"] = "1"
326+
extensions.append("sphinx_qt_documentation") # Errors out w/o Qt installed
263327
else:
264328
autosummary_generate = False
265-
suppress_warnings += ["autodoc", "autosummary", "toc.excluded"]
266329
exclude_patterns += ["reference.rst"]
330+
suppress_warnings += ["autodoc", "autosummary", "toc.excluded"]
267331

268332

269333
# -- 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)