Skip to content

Commit f3c5536

Browse files
authored
Update sphinx multimethod customization to handle toplevel functions (#1932)
* Update sphinx multimethod customization to handle toplevel functions * Use sphinx 9.0 * Resolve sphinx warnings * Update sphinx to 9.1.0
1 parent 8f91271 commit f3c5536

11 files changed

Lines changed: 878 additions & 327 deletions

doc/classreference.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ Topological Classes
3030
Shape
3131
Vertex
3232
Edge
33-
cadquery.occ_impl.shapes.Mixin1D
33+
occ_impl.shapes.Mixin1D
3434
Wire
3535
Face
3636
Shell
37-
cadquery.occ_impl.shapes.Mixin3D
37+
occ_impl.shapes.Mixin3D
3838
Solid
3939
Compound
4040

doc/conf.py

Lines changed: 3 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@
3636
# Add any Sphinx extension module names here, as strings. They can be extensions
3737
# coming with Sphinx (named 'sphinx.ext.*') or your custom ones.
3838
extensions = [
39-
"sphinx.ext.autodoc",
39+
# "sphinx.ext.autodoc",
40+
# "sphinx.ext.autosummary",
41+
"sphinx_autodoc_multimethod", # custom extension; includes autodoc and autosummary
4042
"sphinx.ext.viewcode",
41-
"sphinx.ext.autosummary",
4243
"sphinx.ext.intersphinx",
4344
"cadquery.cq_directive",
4445
"sphinx.ext.mathjax",
45-
"sphinx_autodoc_multimethod",
4646
]
4747

4848
autodoc_typehints = "both"
@@ -293,29 +293,6 @@
293293
# texinfo_show_urls = 'footnote'
294294

295295

296-
patparam = re.compile(r"(\W*):\W*param.*")
297-
298-
299-
def process_docstring_insert_self(app, what, name, obj, options, lines):
300-
"""
301-
Insert self in front of documented params for instance methods
302-
"""
303-
304-
if (
305-
what == "method"
306-
and app.config.autodoc_typehints in ("both", "description")
307-
and app.config.autodoc_typehints_description_target in ("all")
308-
and getattr(obj, "__self__", None) is None
309-
and "self" in obj.__annotations__
310-
):
311-
for i, line in enumerate(lines):
312-
if m := patparam.match(line):
313-
indent = m.group(1)
314-
lines.insert(i, f"{indent}:param self:")
315-
break
316-
317-
318296
def setup(app):
319297

320298
app.add_css_file("tables.css")
321-
app.connect("autodoc-process-docstring", process_docstring_insert_self)

doc/ext/sphinx_autodoc_multimethod.py

Lines changed: 0 additions & 293 deletions
This file was deleted.
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sphinx.ext.autodoc
2+
3+
# see sphinx/ext/autodoc/_dynamic/_signatures.py
4+
from ._dynamic._signatures import _format_signatures
5+
from .process_docstring_multimethod import process_docstring_multimethod
6+
7+
from .autosummary_multimethod import MultimethodAutosummary
8+
9+
sphinx.ext.autodoc._dynamic._loader._format_signatures = _format_signatures
10+
11+
12+
def setup(app):
13+
14+
app.setup_extension("sphinx.ext.autodoc")
15+
app.connect("autodoc-process-docstring", process_docstring_multimethod)
16+
17+
app.setup_extension("sphinx.ext.autosummary")
18+
app.add_directive("autosummary", MultimethodAutosummary, override=True)
19+
20+
return {"parallel_read_safe": True, "parallel_write_safe": True}

0 commit comments

Comments
 (0)