Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 4a80339

Browse files
committed
DOC: Keep supporting older sphinx-gallery
1 parent 6046659 commit 4a80339

File tree

3 files changed

+24
-15
lines changed

3 files changed

+24
-15
lines changed

doc/conf.py

Lines changed: 21 additions & 13 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,8 +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
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
183196

184197
# The following import is only necessary to monkey patch the signature later on
185198
from sphinx_gallery import gen_rst
@@ -237,29 +250,25 @@ def _check_dependencies():
237250
example_dirs += [f'../galleries/{gd}']
238251

239252
sphinx_gallery_conf = {
240-
'backreferences_dir': Path('api') / Path('_as_gen'),
253+
'backreferences_dir': Path('api', '_as_gen'),
241254
# Compression is a significant effort that we skip for local and CI builds.
242255
'compress_images': ('thumbnails', 'images') if is_release_build else (),
243256
'doc_module': ('matplotlib', 'mpl_toolkits'),
244257
'examples_dirs': example_dirs,
245258
'filename_pattern': '^((?!sgskip).)*$',
246259
'gallery_dirs': gallery_dirs,
247-
'image_scrapers': ("sphinxext.util.matplotlib_reduced_latex_scraper", ),
260+
'image_scrapers': (matplotlib_reduced_latex_scraper, ),
248261
'image_srcset': ["2x"],
249262
'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
250263
'matplotlib_animations': True,
251264
'min_reported_time': 1,
252265
'plot_gallery': 'True', # sphinx-gallery/913
253266
'reference_url': {'matplotlib': None},
254267
'remove_config_comments': True,
255-
'reset_modules': (
256-
'matplotlib',
257-
# clear basic_units module to re-register with unit registry on import
258-
"sphinxext.util.clear_basic_unit"
259-
),
260-
'subsection_order': "sphinxext.gallery_order.sectionorder",
268+
'reset_modules': ('matplotlib', clear_basic_units),
269+
'subsection_order': gallery_order_sectionorder,
261270
'thumbnail_size': (320, 224),
262-
'within_subsection_order': "sphinxext.gallery_order.subsectionorder",
271+
'within_subsection_order': gallery_order_subsectionorder,
263272
'capture_repr': (),
264273
'copyfile_regex': r'.*\.rst',
265274
}
@@ -741,7 +750,6 @@ def js_tag_with_cache_busting(js):
741750

742751
if link_github:
743752
import inspect
744-
from packaging.version import parse
745753

746754
extensions.append('sphinx.ext.linkcode')
747755

@@ -797,7 +805,7 @@ def linkcode_resolve(domain, info):
797805
if not fn.startswith(('matplotlib/', 'mpl_toolkits/')):
798806
return None
799807

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

doc/sphinxext/util.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
1616
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
1717

1818

19-
def clear_basic_unit(gallery_conf, fname):
19+
# Clear basic_units module to re-register with unit registry on import.
20+
def clear_basic_units(gallery_conf, fname):
2021
return sys.modules.pop('basic_units', None)

requirements/doc/doc-requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pyyaml
2020
sphinxcontrib-svg2pdfconverter>=1.1.0
2121
sphinx-copybutton
2222
sphinx-design
23+
sphinx-gallery>=0.12.0
2324
sphinx-tags>=0.3.0
24-
sphinx-gallery @ git+https://github.com/larsoner/sphinx-gallery.git@serial

0 commit comments

Comments
 (0)