Content-Length: 492029 | pFad | http://github.com/matplotlib/matplotlib/commit/

6A107146 Adds `plot_skip_execution` config to temporarily disable plot_directi… · matplotlib/matplotlib@a94275a · GitHub
Skip to content

Commit a94275a

Browse files
billbrodtacaswell
andauthored
Adds plot_skip_execution config to temporarily disable plot_directive. (#31270)
* squashed commit adding plot_skip_execution config * MNT: will be in mpl 3.12 --------- Co-authored-by: Thomas A Caswell <tcaswell@gmail.com>
1 parent 4320f31 commit a94275a

3 files changed

Lines changed: 79 additions & 10 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
New config option for ``matplotlib.sphinxext.plot_directive``: ``plot_skip_execution``
2+
--------------------------------------------------------------------------------------
3+
4+
This configuration option allows users to temporarily skip the execution of all
5+
plot directives, not running the code or generating the plots. It is intended to
6+
be used during development to speed up building documentation that contains many
7+
plot directives.
8+
9+
It can be temporarily enabled from the command line by passing ``-D
10+
plot_skip_execution=1`` to ``sphinx-build``, e.g.,: ``make html O="-D
11+
plot_skip_execution=1"``.

lib/matplotlib/sphinxext/plot_directive.py

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,12 @@
162162
The plot_srcset option is incompatible with *singlehtml* builds, and an
163163
error will be raised.
164164
165+
plot_skip_execution
166+
If True, will not run any plot directives. Code, captions, etc. will all
167+
still be rendered, but no plots will be created.
168+
169+
.. versionadded:: 3.12
170+
165171
Notes on how it works
166172
---------------------
167173
@@ -323,6 +329,7 @@ def setup(app):
323329
app.add_config_value('plot_working_directory', None, True)
324330
app.add_config_value('plot_template', None, True)
325331
app.add_config_value('plot_srcset', [], True)
332+
app.add_config_value('plot_skip_execution', False, True)
326333
app.connect('doctree-read', mark_plot_labels)
327334
app.add_css_file('plot_directive.css')
328335
app.connect('build-finished', _copy_css_file)
@@ -925,16 +932,19 @@ def run(arguments, content, options, state_machine, state, lineno):
925932

926933
# make figures
927934
try:
928-
results = render_figures(code=code,
929-
code_path=source_file_name,
930-
output_dir=build_dir,
931-
output_base=output_base,
932-
context=keep_context,
933-
function_name=function_name,
934-
config=config,
935-
context_reset=context_opt == 'reset',
936-
close_figs=context_opt == 'close-figs',
937-
code_includes=source_file_includes)
935+
if config.plot_skip_execution:
936+
results = [(code, [])]
937+
else:
938+
results = render_figures(code=code,
939+
code_path=source_file_name,
940+
output_dir=build_dir,
941+
output_base=output_base,
942+
context=keep_context,
943+
function_name=function_name,
944+
config=config,
945+
context_reset=context_opt == 'reset',
946+
close_figs=context_opt == 'close-figs',
947+
code_includes=source_file_includes)
938948
errors = []
939949
except PlotError as err:
940950
reporter = state.memo.reporter

lib/matplotlib/tests/test_sphinxext.py

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -269,3 +269,51 @@ def plot_file(num, suff=''):
269269
st = ('srcset="../_images/nestedpage2-index-2.png, '
270270
'../_images/nestedpage2-index-2.2x.png 2.00x"')
271271
assert st in (html_dir / 'nestedpage2/index.html').read_text(encoding='utf-8')
272+
273+
274+
def test_plot_skip_execution(tmp_path):
275+
# test that modifying plot_exclude_patterns in config leads to skipping files
276+
shutil.copyfile(tinypages / 'conf.py', tmp_path / 'conf.py')
277+
shutil.copytree(tinypages / '_static', tmp_path / '_static')
278+
shutil.copyfile(tinypages / 'range4.py', tmp_path / 'range4.py')
279+
shutil.copyfile(tinypages / 'range6.py', tmp_path / 'range6.py')
280+
281+
html_dir = tmp_path / '_build' / 'html'
282+
img_dir = html_dir / '_images'
283+
doctree_dir = tmp_path / 'doctrees'
284+
285+
(tmp_path / 'index.rst').write_text("""
286+
.. plot::
287+
288+
plt.plot(range(2))
289+
290+
.. toctree::
291+
292+
script_func
293+
script_nofunc
294+
""")
295+
(tmp_path / 'script_func.rst').write_text("""
296+
##########
297+
Some plots
298+
##########
299+
300+
.. plot:: range6.py range6
301+
302+
.. plot:: range6.py range10
303+
""")
304+
(tmp_path / 'script_nofunc.rst').write_text("""
305+
##########
306+
Some plots
307+
##########
308+
309+
.. plot:: range4.py
310+
""")
311+
312+
# Build the pages with warnings turned into errors
313+
build_sphinx_html(tmp_path, doctree_dir, html_dir,
314+
extra_args=["-D", "plot_skip_execution=1"])
315+
316+
assert not (img_dir / "index-1.png").exists()
317+
assert not (img_dir / "range6_range6.png").exists()
318+
assert not (img_dir / "range6_range10.png").exists()
319+
assert not (img_dir / "range4.png").exists()

0 commit comments

Comments
 (0)








ApplySandwichStrip

pFad - (p)hone/(F)rame/(a)nonymizer/(d)eclutterfier!      Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

Fetched URL: http://github.com/matplotlib/matplotlib/commit/

Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy