19
19
import sys
20
20
from urllib .parse import urlsplit , urlunsplit
21
21
import warnings
22
+ import yaml
22
23
23
24
import matplotlib
24
25
34
35
# are we running circle CI?
35
36
CIRCLECI = 'CIRCLECI' in os .environ
36
37
37
- # shortcuts: subdirectories to not build. Should be relative
38
- # to the doc directory. Note that you cannot skip "users"
39
- # but can skip subdirectories...
40
- #
41
- # Note if any of the sphinx-galleries are skipped then they
42
- # will not be built using sphinx-gallery.
38
+
39
+ def _parse_skip_subdirs_file ():
40
+ """
41
+ Read .mpl_skip_subdirs.yaml for subdirectories to not
42
+ build if we do `make html-skip-subdirs`. Subdirectories
43
+ are relative to the toplevel directory. Note that you
44
+ cannot skip 'users' as it contains the table of contents,
45
+ but you can skip subdirectories of 'users'. Doing this
46
+ can make partial builds very fast.
47
+ """
48
+ default_skip_subdirs = ['users/prev_whats_new/*' , 'api/*' , 'gallery/*' ,
49
+ 'tutorials/*' , 'plot_types/*' , 'devel/*' ]
50
+ try :
51
+ with open (".mpl_skip_subdirs.yaml" , 'r' ) as fin :
52
+ print ('Reading subdirectories to skip from' ,
53
+ '.mpl_skip_subdirs.yaml' )
54
+ out = yaml .full_load (fin )
55
+ return out ['skip_subdirs' ]
56
+ except FileNotFoundError :
57
+ # make a default:
58
+ with open (".mpl_skip_subdirs.yaml" , 'w' ) as fout :
59
+ yamldict = {'skip_subdirs' : default_skip_subdirs ,
60
+ 'comment' : 'For use with make html-skip-subdirs' }
61
+ yaml .dump (yamldict , fout )
62
+ print ('Skipping subdirectories, but .mpl_skip_subdirs.yaml' ,
63
+ 'not found so creating a default one. Edit this file' ,
64
+ 'to customize which diretories are included in build.' )
65
+
66
+ return default_skip_subdirs
67
+
68
+
43
69
skip_subdirs = []
44
- if 'skip_dirs=1' in sys .argv :
45
- skip_subdirs = [
46
- 'users/prev_whats_new/*' ,
47
- 'gallery/*' ,
48
- 'api/*' ,
49
- 'tutorials/*' ,
50
- 'plot_types/*' ,
51
- 'devel/*'
52
- ]
70
+ # triggered via make html-skip-subdirs
71
+ if 'skip_subdirs=1' in sys .argv :
72
+ skip_subdirs = _parse_skip_subdirs_file ()
53
73
54
74
# Parse year using SOURCE_DATE_EPOCH, falling back to current time.
55
75
# https://reproducible-builds.org/specs/source-date-epoch/
@@ -193,13 +213,13 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
193
213
gallery_conf ['image_srcset' ] = []
194
214
return matplotlib_scraper (block , block_vars , gallery_conf , ** kwargs )
195
215
196
- example_dirs = []
197
- if 'gallery /*' not in skip_subdirs :
198
- example_dirs += [ '../examples' ]
199
- if 'tutorials/*' not in skip_subdirs :
200
- example_dirs += [ '../tutorials' ]
201
- if 'plot_types/*' not in skip_subdirs :
202
- example_dirs += [ '../plot_types' ]
216
+ example_dirs = [f'../ { ed } ' for ed in [ 'gallery' , 'tutorials' , 'plot_types' ]
217
+ if f' { ed } /*' not in skip_subdirs ]
218
+ example_dirs = [ '../examples' if d == '../gallery' else d
219
+ for d in example_dirs ]
220
+
221
+ gallery_dirs = [ f' { ed } ' for ed in [ 'gallery' , 'tutorials' , 'plot_types' ]
222
+ if f' { ed } /*' not in skip_subdirs ]
203
223
204
224
sphinx_gallery_conf = {
205
225
'backreferences_dir' : Path ('api' ) / Path ('_as_gen' ),
@@ -208,7 +228,7 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
208
228
'doc_module' : ('matplotlib' , 'mpl_toolkits' ),
209
229
'examples_dirs' : example_dirs ,
210
230
'filename_pattern' : '^((?!sgskip).)*$' ,
211
- 'gallery_dirs' : [ 'gallery' , 'tutorials' , 'plot_types' ] ,
231
+ 'gallery_dirs' : gallery_dirs ,
212
232
'image_scrapers' : (matplotlib_reduced_latex_scraper , ),
213
233
'image_srcset' : ["2x" ],
214
234
'junit' : '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '' ,
@@ -737,6 +757,6 @@ def setup(app):
737
757
bld_type = 'dev'
738
758
else :
739
759
bld_type = 'rel'
740
- app .add_config_value ('skip_dirs ' , 0 , '' )
760
+ app .add_config_value ('skip_subdirs ' , 0 , '' )
741
761
app .add_config_value ('releaselevel' , bld_type , 'env' )
742
762
app .connect ('html-page-context' , add_html_cache_busting , priority = 1000 )
0 commit comments