|
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,8 +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 |
| 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 |
183 | 196 |
|
184 | 197 | # The following import is only necessary to monkey patch the signature later on
|
185 | 198 | from sphinx_gallery import gen_rst
|
@@ -237,29 +250,25 @@ def _check_dependencies():
|
237 | 250 | example_dirs += [f'../galleries/{gd}']
|
238 | 251 |
|
239 | 252 | sphinx_gallery_conf = {
|
240 |
| - 'backreferences_dir': Path('api') / Path('_as_gen'), |
| 253 | + 'backreferences_dir': Path('api', '_as_gen'), |
241 | 254 | # Compression is a significant effort that we skip for local and CI builds.
|
242 | 255 | 'compress_images': ('thumbnails', 'images') if is_release_build else (),
|
243 | 256 | 'doc_module': ('matplotlib', 'mpl_toolkits'),
|
244 | 257 | 'examples_dirs': example_dirs,
|
245 | 258 | 'filename_pattern': '^((?!sgskip).)*$',
|
246 | 259 | 'gallery_dirs': gallery_dirs,
|
247 |
| - 'image_scrapers': ("sphinxext.util.matplotlib_reduced_latex_scraper", ), |
| 260 | + 'image_scrapers': (matplotlib_reduced_latex_scraper, ), |
248 | 261 | 'image_srcset': ["2x"],
|
249 | 262 | 'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
|
250 | 263 | 'matplotlib_animations': True,
|
251 | 264 | 'min_reported_time': 1,
|
252 | 265 | 'plot_gallery': 'True', # sphinx-gallery/913
|
253 | 266 | 'reference_url': {'matplotlib': None},
|
254 | 267 | '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, |
261 | 270 | 'thumbnail_size': (320, 224),
|
262 |
| - 'within_subsection_order': "sphinxext.gallery_order.subsectionorder", |
| 271 | + 'within_subsection_order': gallery_order_subsectionorder, |
263 | 272 | 'capture_repr': (),
|
264 | 273 | 'copyfile_regex': r'.*\.rst',
|
265 | 274 | }
|
@@ -741,7 +750,6 @@ def js_tag_with_cache_busting(js):
|
741 | 750 |
|
742 | 751 | if link_github:
|
743 | 752 | import inspect
|
744 |
| - from packaging.version import parse |
745 | 753 |
|
746 | 754 | extensions.append('sphinx.ext.linkcode')
|
747 | 755 |
|
@@ -797,7 +805,7 @@ def linkcode_resolve(domain, info):
|
797 | 805 | if not fn.startswith(('matplotlib/', 'mpl_toolkits/')):
|
798 | 806 | return None
|
799 | 807 |
|
800 |
| - version = parse(matplotlib.__version__) |
| 808 | + version = parse_version(matplotlib.__version__) |
801 | 809 | tag = 'main' if version.is_devrelease else f'v{version.public}'
|
802 | 810 | return ("https://github.com/matplotlib/matplotlib/blob"
|
803 | 811 | f"/{tag}/lib/{fn}{linespec}")
|
|
0 commit comments