Skip to content

Commit ccb5af5

Browse files
committed
FIX (partial): sphinx_gallery_conf not pickleable
1 parent 8ad5f53 commit ccb5af5

File tree

3 files changed

+28
-21
lines changed

3 files changed

+28
-21
lines changed

doc/conf.py

+4-20
Original file line numberDiff line numberDiff line change
@@ -228,22 +228,6 @@ def _check_dependencies():
228228
}
229229

230230

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-
247231
gallery_dirs = [f'{ed}' for ed in
248232
['gallery', 'tutorials', 'plot_types', 'users/explain']
249233
if f'{ed}/*' not in skip_subdirs]
@@ -261,7 +245,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
261245
'examples_dirs': example_dirs,
262246
'filename_pattern': '^((?!sgskip).)*$',
263247
'gallery_dirs': gallery_dirs,
264-
'image_scrapers': (matplotlib_reduced_latex_scraper, ),
248+
'image_scrapers': ("sphinxext.util.matplotlib_reduced_latex_scraper", ),
265249
'image_srcset': ["2x"],
266250
'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
267251
'matplotlib_animations': True,
@@ -272,11 +256,11 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
272256
'reset_modules': (
273257
'matplotlib',
274258
# clear basic_units module to re-register with unit registry on import
275-
lambda gallery_conf, fname: sys.modules.pop('basic_units', None)
259+
"sphinxext.util.clear_basic_unit"
276260
),
277-
'subsection_order': gallery_order.sectionorder,
261+
'subsection_order': "sphinxext.gallery_order.sectionorder",
278262
'thumbnail_size': (320, 224),
279-
'within_subsection_order': gallery_order.subsectionorder,
263+
'within_subsection_order': "sphinxext.gallery_order.subsectionorder",
280264
'capture_repr': (),
281265
'copyfile_regex': r'.*\.rst',
282266
}

doc/sphinxext/gallery_order.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def __call__(self, item):
105105
explicit_subsection_order = [item + ".py" for item in list_all]
106106

107107

108-
class MplExplicitSubOrder:
108+
class MplExplicitSubOrder(ExplicitOrder):
109109
"""For use within the 'within_subsection_order' key."""
110110
def __init__(self, src_dir):
111111
self.src_dir = src_dir # src_dir is unused here
@@ -119,6 +119,9 @@ def __call__(self, item):
119119
# ensure not explicitly listed items come last.
120120
return "zzz" + item
121121

122+
# from sphinx.confing import is_serializable
123+
# assert is_serializable(MplExplicitSubOrder)
124+
122125

123126
# Provide the above classes for use in conf.py
124127
sectionorder = MplExplicitOrder(explicit_order_folders)

doc/sphinxext/util.py

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import sys
2+
3+
# Sphinx gallery configuration
4+
def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
5+
**kwargs):
6+
"""
7+
Reduce srcset when creating a PDF.
8+
9+
Because sphinx-gallery runs *very* early, we cannot modify this even in the
10+
earliest builder-inited signal. Thus we do it at scraping time.
11+
"""
12+
from sphinx_gallery.scrapers import matplotlib_scraper
13+
14+
if gallery_conf['builder_name'] == 'latex':
15+
gallery_conf['image_srcset'] = []
16+
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
17+
18+
19+
def clear_basic_unit(gallery_conf, fname):
20+
return sys.modules.pop('basic_units', None)

0 commit comments

Comments
 (0)