Skip to content

Commit 00b53a6

Browse files
committed
DOC/BUILD: make yaml version of skip list
1 parent 68e3df1 commit 00b53a6

File tree

3 files changed

+52
-30
lines changed

3 files changed

+52
-30
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ examples/tests/*
8282
!examples/tests/backend_driver_sgskip.py
8383
result_images
8484
doc/_static/constrained_layout*.png
85+
doc/.mpl_skip_subdirs.yaml
8586

8687
# Nose/Pytest generated files #
8788
###############################

doc/Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ html-noplot:
3333
@echo
3434
@echo "Build finished. The HTML pages are in $(BUILDDIR)/html."
3535

36-
# This will skip the directories listed in the skip_subdirs variable
37-
# in conf.py. Edit this by hand if you want to change what sections
38-
# of the docs get built. Can be much faster. However, reset conf.py
39-
# to original values before pushig to github.
40-
html-skip-dirs:
41-
$(SPHINXBUILD) -D skip_dirs=1 -b html $(SOURCEDIR) $(BUILDDIR)/html $(SPHINXOPTS) $(O)
36+
# This will skip the subdirectories listed in .mpl_skip_subdirs.yaml If
37+
# this file does not exist, one will be created for you. This option useful
38+
# to quickly build parts of the docs, but the resulting build will not
39+
# have all the crosslinks etc.
40+
html-skip-subdirs:
41+
$(SPHINXBUILD) -D skip_subdirs=1 -b html $(SOURCEDIR) $(BUILDDIR)/html $(SPHINXOPTS) $(O)
4242

4343
# Catch-all target: route all unknown targets to Sphinx using the new
4444
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).

doc/conf.py

+45-24
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import sys
2020
from urllib.parse import urlsplit, urlunsplit
2121
import warnings
22+
import yaml
2223

2324
import matplotlib
2425

@@ -34,22 +35,41 @@
3435
# are we running circle CI?
3536
CIRCLECI = 'CIRCLECI' in os.environ
3637

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+
4369
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()
5373

5474
# Parse year using SOURCE_DATE_EPOCH, falling back to current time.
5575
# https://reproducible-builds.org/specs/source-date-epoch/
@@ -193,22 +213,23 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
193213
gallery_conf['image_srcset'] = []
194214
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
195215

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]
203223

224+
print('EXAMPLES', example_dirs)
204225
sphinx_gallery_conf = {
205226
'backreferences_dir': Path('api') / Path('_as_gen'),
206227
# Compression is a significant effort that we skip for local and CI builds.
207228
'compress_images': ('thumbnails', 'images') if is_release_build else (),
208229
'doc_module': ('matplotlib', 'mpl_toolkits'),
209230
'examples_dirs': example_dirs,
210231
'filename_pattern': '^((?!sgskip).)*$',
211-
'gallery_dirs': ['gallery', 'tutorials', 'plot_types'],
232+
'gallery_dirs': gallery_dirs,
212233
'image_scrapers': (matplotlib_reduced_latex_scraper, ),
213234
'image_srcset': ["2x"],
214235
'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
@@ -737,6 +758,6 @@ def setup(app):
737758
bld_type = 'dev'
738759
else:
739760
bld_type = 'rel'
740-
app.add_config_value('skip_dirs', 0, '')
761+
app.add_config_value('skip_subdirs', 0, '')
741762
app.add_config_value('releaselevel', bld_type, 'env')
742763
app.connect('html-page-context', add_html_cache_busting, priority=1000)

0 commit comments

Comments
 (0)