Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2564db4

Browse filesBrowse files
authored
Merge pull request #28190 from meeseeksmachine/auto-backport-of-pr-28103-on-v3.9.x
Backport PR #28103 on branch v3.9.x ([DOC]: Fix compatibility with sphinx-gallery 0.16)
2 parents c1f07ba + 29e77e3 commit 2564db4
Copy full SHA for 2564db4

File tree

5 files changed

+48
-35
lines changed
Filter options

5 files changed

+48
-35
lines changed

‎doc/conf.py

Copy file name to clipboardExpand all lines: doc/conf.py
+21-30Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from urllib.parse import urlsplit, urlunsplit
2323
import warnings
2424

25+
from packaging.version import parse as parse_version
2526
import sphinx
2627
import yaml
2728

@@ -178,9 +179,20 @@ def _check_dependencies():
178179

179180

180181
# Import only after checking for dependencies.
181-
# gallery_order.py from the sphinxext folder provides the classes that
182-
# allow custom ordering of sections and subsections of the gallery
183-
import sphinxext.gallery_order as gallery_order
182+
import sphinx_gallery
183+
184+
if parse_version(sphinx_gallery.__version__) >= parse_version('0.16.0'):
185+
gallery_order_sectionorder = 'sphinxext.gallery_order.sectionorder'
186+
gallery_order_subsectionorder = 'sphinxext.gallery_order.subsectionorder'
187+
clear_basic_units = 'sphinxext.util.clear_basic_units'
188+
matplotlib_reduced_latex_scraper = 'sphinxext.util.matplotlib_reduced_latex_scraper'
189+
else:
190+
# gallery_order.py from the sphinxext folder provides the classes that
191+
# allow custom ordering of sections and subsections of the gallery
192+
from sphinxext.gallery_order import (
193+
sectionorder as gallery_order_sectionorder,
194+
subsectionorder as gallery_order_subsectionorder)
195+
from sphinxext.util import clear_basic_units, matplotlib_reduced_latex_scraper
184196

185197
# The following import is only necessary to monkey patch the signature later on
186198
from sphinx_gallery import gen_rst
@@ -228,22 +240,6 @@ def _check_dependencies():
228240
}
229241

230242

231-
# Sphinx gallery configuration
232-
233-
def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
234-
**kwargs):
235-
"""
236-
Reduce srcset when creating a PDF.
237-
238-
Because sphinx-gallery runs *very* early, we cannot modify this even in the
239-
earliest builder-inited signal. Thus we do it at scraping time.
240-
"""
241-
from sphinx_gallery.scrapers import matplotlib_scraper
242-
243-
if gallery_conf['builder_name'] == 'latex':
244-
gallery_conf['image_srcset'] = []
245-
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
246-
247243
gallery_dirs = [f'{ed}' for ed in
248244
['gallery', 'tutorials', 'plot_types', 'users/explain']
249245
if f'{ed}/*' not in skip_subdirs]
@@ -254,7 +250,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
254250
example_dirs += [f'../galleries/{gd}']
255251

256252
sphinx_gallery_conf = {
257-
'backreferences_dir': Path('api') / Path('_as_gen'),
253+
'backreferences_dir': Path('api', '_as_gen'),
258254
# Compression is a significant effort that we skip for local and CI builds.
259255
'compress_images': ('thumbnails', 'images') if is_release_build else (),
260256
'doc_module': ('matplotlib', 'mpl_toolkits'),
@@ -269,14 +265,10 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
269265
'plot_gallery': 'True', # sphinx-gallery/913
270266
'reference_url': {'matplotlib': None},
271267
'remove_config_comments': True,
272-
'reset_modules': (
273-
'matplotlib',
274-
# clear basic_units module to re-register with unit registry on import
275-
lambda gallery_conf, fname: sys.modules.pop('basic_units', None)
276-
),
277-
'subsection_order': gallery_order.sectionorder,
268+
'reset_modules': ('matplotlib', clear_basic_units),
269+
'subsection_order': gallery_order_sectionorder,
278270
'thumbnail_size': (320, 224),
279-
'within_subsection_order': gallery_order.subsectionorder,
271+
'within_subsection_order': gallery_order_subsectionorder,
280272
'capture_repr': (),
281273
'copyfile_regex': r'.*\.rst',
282274
}
@@ -333,7 +325,7 @@ def gallery_image_warning_filter(record):
333325
:class: sphx-glr-download-link-note
334326
335327
:ref:`Go to the end <sphx_glr_download_{1}>`
336-
to download the full example code{2}
328+
to download the full example code.{2}
337329
338330
.. rst-class:: sphx-glr-example-title
339331
@@ -758,7 +750,6 @@ def js_tag_with_cache_busting(js):
758750

759751
if link_github:
760752
import inspect
761-
from packaging.version import parse
762753

763754
extensions.append('sphinx.ext.linkcode')
764755

@@ -814,7 +805,7 @@ def linkcode_resolve(domain, info):
814805
if not fn.startswith(('matplotlib/', 'mpl_toolkits/')):
815806
return None
816807

817-
version = parse(matplotlib.__version__)
808+
version = parse_version(matplotlib.__version__)
818809
tag = 'main' if version.is_devrelease else f'v{version.public}'
819810
return ("https://github.com/matplotlib/matplotlib/blob"
820811
f"/{tag}/lib/{fn}{linespec}")

‎doc/sphinxext/gallery_order.py

Copy file name to clipboardExpand all lines: doc/sphinxext/gallery_order.py
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __call__(self, item):
105105
explicit_subsection_order = [item + ".py" for item in list_all]
106106

107107

108-
class MplExplicitSubOrder:
108+
class MplExplicitSubOrder(ExplicitOrder):
109109
"""For use within the 'within_subsection_order' key."""
110110
def __init__(self, src_dir):
111111
self.src_dir = src_dir # src_dir is unused here

‎doc/sphinxext/util.py

Copy file name to clipboard
+21Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import sys
2+
3+
4+
def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
5+
**kwargs):
6+
"""
7+
Reduce srcset when creating a PDF.
8+
9+
Because sphinx-gallery runs *very* early, we cannot modify this even in the
10+
earliest builder-inited signal. Thus we do it at scraping time.
11+
"""
12+
from sphinx_gallery.scrapers import matplotlib_scraper
13+
14+
if gallery_conf['builder_name'] == 'latex':
15+
gallery_conf['image_srcset'] = []
16+
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
17+
18+
19+
# Clear basic_units module to re-register with unit registry on import.
20+
def clear_basic_units(gallery_conf, fname):
21+
return sys.modules.pop('basic_units', None)

‎lib/matplotlib/tests/test_doc.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_doc.py
+3-2Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ def test_sphinx_gallery_example_header():
99
EXAMPLE_HEADER, this test will start to fail. In that case, please update
1010
the monkey-patching of EXAMPLE_HEADER in conf.py.
1111
"""
12-
gen_rst = pytest.importorskip('sphinx_gallery.gen_rst')
12+
pytest.importorskip('sphinx_gallery', minversion='0.16.0')
13+
from sphinx_gallery import gen_rst
1314

1415
EXAMPLE_HEADER = """
1516
.. DO NOT EDIT.
@@ -24,7 +25,7 @@ def test_sphinx_gallery_example_header():
2425
:class: sphx-glr-download-link-note
2526
2627
:ref:`Go to the end <sphx_glr_download_{1}>`
27-
to download the full example code{2}
28+
to download the full example code.{2}
2829
2930
.. rst-class:: sphx-glr-example-title
3031

‎requirements/doc/doc-requirements.txt

Copy file name to clipboardExpand all lines: requirements/doc/doc-requirements.txt
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# Install the documentation requirements with:
88
# pip install -r requirements/doc/doc-requirements.txt
99
#
10-
sphinx>=3.0.0,!=6.1.2,!=7.3.*
10+
sphinx>=3.0.0,!=6.1.2
1111
colorspacious
1212
ipython
1313
ipywidgets
@@ -18,7 +18,7 @@ pydata-sphinx-theme~=0.15.0
1818
mpl-sphinx-theme~=3.8.0
1919
pyyaml
2020
sphinxcontrib-svg2pdfconverter>=1.1.0
21-
sphinx-gallery>=0.12.0
2221
sphinx-copybutton
2322
sphinx-design
23+
sphinx-gallery>=0.12.0
2424
sphinx-tags>=0.3.0

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.