Skip to content

Commit c9f7289

Browse files
committed
DOC: reinstate "codex" search term
Our monkeypatching of sphinx-gallery's EXAMPLE_HEADER in conf.py no longer works when using the parallel build option. One way around this is to monkey-patch for each individual example by adding a function that does it in the "reset_modules" config option. Closes #29542
1 parent 420750c commit c9f7289

File tree

3 files changed

+34
-29
lines changed

3 files changed

+34
-29
lines changed

doc/conf.py

Lines changed: 1 addition & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -208,8 +208,6 @@ def _check_dependencies():
208208
else:
209209
sg_matplotlib_animations = True
210210

211-
# The following import is only necessary to monkey patch the signature later on
212-
from sphinx_gallery import gen_rst
213211

214212
# Prevent plt.show() from emitting a non-GUI backend warning.
215213
warnings.filterwarnings('ignore', category=UserWarning,
@@ -307,7 +305,7 @@ def autodoc_process_bases(app, name, obj, options, bases):
307305
'reference_url': {'matplotlib': None, 'mpl_toolkits': None},
308306
'prefer_full_module': {r'mpl_toolkits\.'},
309307
'remove_config_comments': True,
310-
'reset_modules': ('matplotlib', clear_basic_units),
308+
'reset_modules': ('matplotlib', clear_basic_units, 'sphinxext.util.patch_header'),
311309
'subsection_order': gallery_order_sectionorder,
312310
'thumbnail_size': (320, 224),
313311
'within_subsection_order': gallery_order_subsectionorder,
@@ -355,31 +353,6 @@ def gallery_image_warning_filter(record):
355353
mathmpl_fontsize = 11.0
356354
mathmpl_srcset = ['2x']
357355

358-
# Monkey-patching gallery header to include search keywords
359-
gen_rst.EXAMPLE_HEADER = """
360-
.. DO NOT EDIT.
361-
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
362-
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
363-
.. "{0}"
364-
.. LINE NUMBERS ARE GIVEN BELOW.
365-
366-
.. only:: html
367-
368-
.. meta::
369-
:keywords: codex
370-
371-
.. note::
372-
:class: sphx-glr-download-link-note
373-
374-
:ref:`Go to the end <sphx_glr_download_{1}>`
375-
to download the full example code{2}
376-
377-
.. rst-class:: sphx-glr-example-title
378-
379-
.. _sphx_glr_{1}:
380-
381-
"""
382-
383356
# Add any paths that contain templates here, relative to this directory.
384357
templates_path = ['_templates']
385358

doc/sphinxext/util.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import sys
22

3+
from sphinx_gallery import gen_rst
4+
35

46
def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
57
**kwargs):
@@ -19,3 +21,33 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
1921
# Clear basic_units module to re-register with unit registry on import.
2022
def clear_basic_units(gallery_conf, fname):
2123
return sys.modules.pop('basic_units', None)
24+
25+
26+
# Monkey-patching gallery header to include search keywords
27+
EXAMPLE_HEADER = """
28+
.. DO NOT EDIT.
29+
.. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY.
30+
.. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE:
31+
.. "{0}"
32+
.. LINE NUMBERS ARE GIVEN BELOW.
33+
34+
.. only:: html
35+
36+
.. meta::
37+
:keywords: codex
38+
39+
.. note::
40+
:class: sphx-glr-download-link-note
41+
42+
:ref:`Go to the end <sphx_glr_download_{1}>`
43+
to download the full example code{2}
44+
45+
.. rst-class:: sphx-glr-example-title
46+
47+
.. _sphx_glr_{1}:
48+
49+
"""
50+
51+
52+
def patch_header(gallery_conf, fname):
53+
gen_rst.EXAMPLE_HEADER = EXAMPLE_HEADER

lib/matplotlib/tests/test_doc.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def test_sphinx_gallery_example_header():
77
This test monitors that the version we have copied is still the same as
88
the EXAMPLE_HEADER in sphinx-gallery. If sphinx-gallery changes its
99
EXAMPLE_HEADER, this test will start to fail. In that case, please update
10-
the monkey-patching of EXAMPLE_HEADER in conf.py.
10+
the monkey-patching of EXAMPLE_HEADER in sphinxext/util.py.
1111
"""
1212
pytest.importorskip('sphinx_gallery', minversion='0.20.0')
1313
from sphinx_gallery import gen_rst

0 commit comments

Comments
 (0)