Skip to content

Commit 651a874

Browse files
authored
Merge pull request matplotlib#24907 from jklymak/doc-conf-with-shortcuts
DOC/BUILD add ability for conf to skip whole sections
2 parents 99d39bd + 2541f23 commit 651a874

File tree

7 files changed

+70
-3
lines changed

7 files changed

+70
-3
lines changed

Diff for: .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
###############################

Diff for: doc/Makefile

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

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_sub_dirs=1 -b html $(SOURCEDIR) $(BUILDDIR)/html $(SPHINXOPTS) $(O)
42+
3643
# Catch-all target: route all unknown targets to Sphinx using the new
3744
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
3845
%: Makefile

Diff for: doc/conf.py

+48-3
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,6 +35,42 @@
3435
# are we running circle CI?
3536
CIRCLECI = 'CIRCLECI' in os.environ
3637

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+
3774
# Parse year using SOURCE_DATE_EPOCH, falling back to current time.
3875
# https://reproducible-builds.org/specs/source-date-epoch/
3976
sourceyear = datetime.utcfromtimestamp(
@@ -80,9 +117,11 @@
80117
]
81118

82119
exclude_patterns = [
83-
'api/prev_api_changes/api_changes_*/*',
120+
'api/prev_api_changes/api_changes_*/*'
84121
]
85122

123+
exclude_patterns += skip_subdirs
124+
86125

87126
def _check_dependencies():
88127
names = {
@@ -174,15 +213,20 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
174213
gallery_conf['image_srcset'] = []
175214
return matplotlib_scraper(block, block_vars, gallery_conf, **kwargs)
176215

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

178222
sphinx_gallery_conf = {
179223
'backreferences_dir': Path('api') / Path('_as_gen'),
180224
# Compression is a significant effort that we skip for local and CI builds.
181225
'compress_images': ('thumbnails', 'images') if is_release_build else (),
182226
'doc_module': ('matplotlib', 'mpl_toolkits'),
183-
'examples_dirs': ['../examples', '../tutorials', '../plot_types'],
227+
'examples_dirs': example_dirs,
184228
'filename_pattern': '^((?!sgskip).)*$',
185-
'gallery_dirs': ['gallery', 'tutorials', 'plot_types'],
229+
'gallery_dirs': gallery_dirs,
186230
'image_scrapers': (matplotlib_reduced_latex_scraper, ),
187231
'image_srcset': ["2x"],
188232
'junit': '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '',
@@ -711,5 +755,6 @@ def setup(app):
711755
bld_type = 'dev'
712756
else:
713757
bld_type = 'rel'
758+
app.add_config_value('skip_sub_dirs', 0, '')
714759
app.add_config_value('releaselevel', bld_type, 'env')
715760
app.connect('html-page-context', add_html_cache_busting, priority=1000)

Diff for: doc/devel/documenting_mpl.rst

+6
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ Other useful invocations include
7171
# save time.
7272
make html-noplot
7373
74+
# Build the html documentation, but skip specific subdirectories. If a gallery
75+
# directory is skipped, the gallery images are not generated. The first
76+
# time this is run, it creates ``.mpl_skip_subdirs.yaml`` which can be edited
77+
# to add or remove subdirectories
78+
make html-skip-subdirs
79+
7480
# Delete built files. May help if you get errors about missing paths or
7581
# broken links.
7682
make clean

Diff for: doc/make.bat

+6
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ if errorlevel 9009 (
2929

3030
if "%1" == "" goto help
3131
if "%1" == "html-noplot" goto html-noplot
32+
if "%1" == "html-skip-subdirs" goto html-skip-subdirs
3233
if "%1" == "show" goto show
3334

3435
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
@@ -52,6 +53,11 @@ goto end
5253
%SPHINXBUILD% -M html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -D plot_gallery=0
5354
goto end
5455

56+
:html-skip-subdirs
57+
%SPHINXBUILD% -M html %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O% -D skip_sub_dirs=1
58+
goto end
59+
60+
5561
:show
5662
python -m webbrowser -t "%~dp0\build\html\index.html"
5763

Diff for: environment.yml

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ dependencies:
3333
- numpydoc>=0.8
3434
- packaging
3535
- pydata-sphinx-theme
36+
- pyyaml
3637
- sphinx>=1.8.1,!=2.0.0
3738
- sphinx-copybutton
3839
- sphinx-gallery>=0.10

Diff for: requirements/doc/doc-requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ numpydoc>=1.0
1515
packaging>=20
1616
pydata-sphinx-theme>=0.12.0
1717
mpl-sphinx-theme
18+
pyyaml
1819
sphinxcontrib-svg2pdfconverter>=1.1.0
1920
sphinx-gallery>=0.10
2021
sphinx-copybutton

0 commit comments

Comments
 (0)