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,21 @@ 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
+
183
+ import sphinx_gallery
184
+
185
+ if parse_version (sphinx_gallery .__version__ ) >= parse_version ('0.16.0' ):
186
+ matplotlib_reduced_latex_scraper = 'sphinxext.matplotlib_reduced_latex_scraper'
187
+ reset_modules_basic_units = 'sphinxext.reset_modules_basic_units'
188
+ gallery_order_sectionorder = 'sphinxext.gallery_order.sectionorder'
189
+ gallery_order_subsectionorder = 'sphinxext.gallery_order.subsectionorder'
190
+ else :
191
+ # gallery_order.py from the sphinxext folder provides the classes that
192
+ # allow custom ordering of sections and subsections of the gallery
193
+ from sphinxext .gallery_order import sectionorder as gallery_order_sectionorder
194
+ from sphinxext .gallery_order import subsectionorder as gallery_order_subsectionorder
195
+ from sphinxext import matplotlib_reduced_latex_scraper
196
+ from sphinxext import reset_modules_basic_units
184
197
185
198
# The following import is only necessary to monkey patch the signature later on
186
199
from sphinx_gallery import gen_rst
@@ -230,20 +243,6 @@ def _check_dependencies():
230
243
231
244
# Sphinx gallery configuration
232
245
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
246
gallery_dirs = [f'{ ed } ' for ed in
248
247
['gallery' , 'tutorials' , 'plot_types' , 'users/explain' ]
249
248
if f'{ ed } /*' not in skip_subdirs ]
@@ -254,7 +253,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
254
253
example_dirs += [f'../galleries/{ gd } ' ]
255
254
256
255
sphinx_gallery_conf = {
257
- 'backreferences_dir' : Path ('api' ) / Path ( '_as_gen' ),
256
+ 'backreferences_dir' : Path ('api' , '_as_gen' ),
258
257
# Compression is a significant effort that we skip for local and CI builds.
259
258
'compress_images' : ('thumbnails' , 'images' ) if is_release_build else (),
260
259
'doc_module' : ('matplotlib' , 'mpl_toolkits' ),
@@ -269,14 +268,10 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
269
268
'plot_gallery' : 'True' , # sphinx-gallery/913
270
269
'reference_url' : {'matplotlib' : None },
271
270
'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 ,
271
+ 'reset_modules' : ('matplotlib' , reset_modules_basic_units ),
272
+ 'subsection_order' : gallery_order_sectionorder ,
278
273
'thumbnail_size' : (320 , 224 ),
279
- 'within_subsection_order' : gallery_order . subsectionorder ,
274
+ 'within_subsection_order' : gallery_order_subsectionorder ,
280
275
'capture_repr' : (),
281
276
'copyfile_regex' : r'.*\.rst' ,
282
277
}
@@ -333,7 +328,7 @@ def gallery_image_warning_filter(record):
333
328
:class: sphx-glr-download-link-note
334
329
335
330
:ref:`Go to the end <sphx_glr_download_{1}>`
336
- to download the full example code{2}
331
+ to download the full example code. {2}
337
332
338
333
.. rst-class:: sphx-glr-example-title
339
334
@@ -758,7 +753,6 @@ def js_tag_with_cache_busting(js):
758
753
759
754
if link_github :
760
755
import inspect
761
- from packaging .version import parse
762
756
763
757
extensions .append ('sphinx.ext.linkcode' )
764
758
@@ -814,7 +808,7 @@ def linkcode_resolve(domain, info):
814
808
if not fn .startswith (('matplotlib/' , 'mpl_toolkits/' )):
815
809
return None
816
810
817
- version = parse (matplotlib .__version__ )
811
+ version = parse_version (matplotlib .__version__ )
818
812
tag = 'main' if version .is_devrelease else f'v{ version .public } '
819
813
return ("https://github.com/matplotlib/matplotlib/blob"
820
814
f"/{ tag } /lib/{ fn } { linespec } " )
0 commit comments