Skip to content

Commit dad615a

Browse files
authored
MNT Fix extension for sphinx 3.0 (#17724)
1 parent 67e24a4 commit dad615a

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ def setup(app):
414414

415415
# Used by custom extension: `custom_autosummary_new_suffix` to change the
416416
# suffix of the following functions. This works around the issue with
417-
# `sklearn.cluster.dbscan` overlapping with `klearn.cluster.DBSCAN` on
417+
# `sklearn.cluster.dbscan` overlapping with `sklearn.cluster.DBSCAN` on
418418
# case insensitive file systems.
419419
custom_autosummary_names_with_new_suffix = {
420420
'sklearn.cluster.dbscan',

doc/sphinxext/custom_autosummary_new_suffix.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
```
2020
"""
2121
import os
22-
import inspect
22+
import sphinx
2323
from contextlib import contextmanager
2424

2525
from sphinx.ext.autosummary import get_rst_suffix
@@ -48,7 +48,6 @@ def custom_os_path_join(a, *p):
4848

4949

5050
def process_generate_options_custom_files(app):
51-
5251
orig_suffix = get_rst_suffix(app)
5352
new_suffix = app.config.custom_autosummary_new_suffix
5453
generated_dirname = app.config.custom_autosummary_generated_dirname
@@ -70,12 +69,20 @@ def setup(app):
7069
app.add_config_value(
7170
'custom_autosummary_generated_dirname', '', None)
7271

73-
# Override process_generate_options added by sphinx.ext.autosummary
74-
builder_inited_listeners = app.events.listeners["builder-inited"]
72+
if sphinx.version_info[0] <= 2:
73+
raise ModuleNotFoundError("Please install Sphinx >= 3.0 in order "
74+
"to build docs")
7575

76-
for listener_id, obj in builder_inited_listeners.items():
77-
if (inspect.isfunction(obj)
78-
and obj.__name__ == "process_generate_options"):
79-
builder_inited_listeners[listener_id] = \
80-
process_generate_options_custom_files
76+
# Find listener id for process_generate_options added by
77+
process_generate_options_id = None
78+
builder_inited_listeners = app.events.listeners["builder-inited"]
79+
for event_listener in builder_inited_listeners:
80+
func = event_listener.handler
81+
if func.__name__ == "process_generate_options":
82+
process_generate_options_id = event_listener.id
8183
break
84+
assert process_generate_options_id is not None
85+
86+
# Override process_generate_options added by sphinx.ext.autosummary
87+
app.disconnect(process_generate_options_id)
88+
app.connect("builder-inited", process_generate_options_custom_files)

0 commit comments

Comments
 (0)