|
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 |
|
| 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 directories are included in build.') |
| 65 | + |
| 66 | + return default_skip_subdirs |
| 67 | + |
| 68 | + |
| 69 | +skip_subdirs = [] |
| 70 | +# triggered via make html-skip-subdirs |
| 71 | +if 'skip_sub_dirs=1' in sys.argv: |
| 72 | + skip_subdirs = _parse_skip_subdirs_file() |
| 73 | + |
37 | 74 | # Parse year using SOURCE_DATE_EPOCH, falling back to current time.
|
38 | 75 | # https://reproducible-builds.org/specs/source-date-epoch/
|
39 | 76 | sourceyear = datetime.utcfromtimestamp(
|
|
80 | 117 | ]
|
81 | 118 |
|
82 | 119 | exclude_patterns = [
|
83 |
| - 'api/prev_api_changes/api_changes_*/*', |
| 120 | + 'api/prev_api_changes/api_changes_*/*' |
84 | 121 | ]
|
85 | 122 |
|
| 123 | +exclude_patterns += skip_subdirs |
| 124 | + |
86 | 125 |
|
87 | 126 | def _check_dependencies():
|
88 | 127 | names = {
|
@@ -174,15 +213,20 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
|
174 | 213 | gallery_conf['image_srcset'] = []
|
175 | 214 | return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
|
176 | 215 |
|
| 216 | +gallery_dirs = [f'{ed}' for ed in ['gallery', 'tutorials', 'plot_types'] |
| 217 | + if f'{ed}/*' not in skip_subdirs] |
| 218 | + |
| 219 | +example_dirs = [f'../{gd}'.replace('gallery', 'examples') for gd in |
| 220 | + gallery_dirs] |
177 | 221 |
|
178 | 222 | sphinx_gallery_conf = {
|
179 | 223 | 'backreferences_dir': Path('api') / Path('_as_gen'),
|
180 | 224 | # Compression is a significant effort that we skip for local and CI builds.
|
181 | 225 | 'compress_images': ('thumbnails', 'images') if is_release_build else (),
|
182 | 226 | 'doc_module': ('matplotlib', 'mpl_toolkits'),
|
183 |
| - 'examples_dirs': ['../examples', '../tutorials', '../plot_types'], |
| 227 | + 'examples_dirs': example_dirs, |
184 | 228 | 'filename_pattern': '^((?!sgskip).)*$',
|
185 |
| - 'gallery_dirs': ['gallery', 'tutorials', 'plot_types'], |
| 229 | + 'gallery_dirs': gallery_dirs, |
186 | 230 | 'image_scrapers': (matplotlib_reduced_latex_scraper, ),
|
187 | 231 | 'image_srcset': ["2x"],
|
188 | 232 | 'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
|
@@ -711,5 +755,6 @@ def setup(app):
|
711 | 755 | bld_type = 'dev'
|
712 | 756 | else:
|
713 | 757 | bld_type = 'rel'
|
| 758 | + app.add_config_value('skip_sub_dirs', 0, '') |
714 | 759 | app.add_config_value('releaselevel', bld_type, 'env')
|
715 | 760 | app.connect('html-page-context', add_html_cache_busting, priority=1000)
|
0 commit comments