2222from urllib .parse import urlsplit , urlunsplit
2323import warnings
2424
25+ from packaging .version import parse as parse_version
2526import sphinx
2627import 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
186198from 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-
247243gallery_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
256252sphinx_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
759751if 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 } " )
0 commit comments