22
22
from urllib .parse import urlsplit , urlunsplit
23
23
import warnings
24
24
25
+ from packaging .version import parse as parse_version
25
26
import sphinx
26
27
import yaml
27
28
@@ -178,9 +179,20 @@ def _check_dependencies():
178
179
179
180
180
181
# 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
184
196
185
197
# The following import is only necessary to monkey patch the signature later on
186
198
from sphinx_gallery import gen_rst
@@ -228,22 +240,6 @@ def _check_dependencies():
228
240
}
229
241
230
242
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
-
247
243
gallery_dirs = [f'{ ed } ' for ed in
248
244
['gallery' , 'tutorials' , 'plot_types' , 'users/explain' ]
249
245
if f'{ ed } /*' not in skip_subdirs ]
@@ -254,7 +250,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
254
250
example_dirs += [f'../galleries/{ gd } ' ]
255
251
256
252
sphinx_gallery_conf = {
257
- 'backreferences_dir' : Path ('api' ) / Path ( '_as_gen' ),
253
+ 'backreferences_dir' : Path ('api' , '_as_gen' ),
258
254
# Compression is a significant effort that we skip for local and CI builds.
259
255
'compress_images' : ('thumbnails' , 'images' ) if is_release_build else (),
260
256
'doc_module' : ('matplotlib' , 'mpl_toolkits' ),
@@ -269,14 +265,10 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
269
265
'plot_gallery' : 'True' , # sphinx-gallery/913
270
266
'reference_url' : {'matplotlib' : None },
271
267
'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 ,
278
270
'thumbnail_size' : (320 , 224 ),
279
- 'within_subsection_order' : gallery_order . subsectionorder ,
271
+ 'within_subsection_order' : gallery_order_subsectionorder ,
280
272
'capture_repr' : (),
281
273
'copyfile_regex' : r'.*\.rst' ,
282
274
}
@@ -333,7 +325,7 @@ def gallery_image_warning_filter(record):
333
325
:class: sphx-glr-download-link-note
334
326
335
327
: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}
337
329
338
330
.. rst-class:: sphx-glr-example-title
339
331
@@ -758,7 +750,6 @@ def js_tag_with_cache_busting(js):
758
750
759
751
if link_github :
760
752
import inspect
761
- from packaging .version import parse
762
753
763
754
extensions .append ('sphinx.ext.linkcode' )
764
755
@@ -814,7 +805,7 @@ def linkcode_resolve(domain, info):
814
805
if not fn .startswith (('matplotlib/' , 'mpl_toolkits/' )):
815
806
return None
816
807
817
- version = parse (matplotlib .__version__ )
808
+ version = parse_version (matplotlib .__version__ )
818
809
tag = 'main' if version .is_devrelease else f'v{ version .public } '
819
810
return ("https://github.com/matplotlib/matplotlib/blob"
820
811
f"/{ tag } /lib/{ fn } { linespec } " )
0 commit comments