Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 348b913

Browse files
committed
Rewrite plot format detection from sphinx build target
The original implementation broke the sphinx config state detection for caching, so that the cache was always invalidated.
1 parent a2ddfc0 commit 348b913

File tree

1 file changed

+10
-18
lines changed

1 file changed

+10
-18
lines changed

doc/conf.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,16 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
278278
# Plot directive configuration
279279
# ----------------------------
280280

281-
plot_formats = [('png', 100), ('pdf', 100)]
281+
# For speedup, decide which plot_formats to build based on build targets:
282+
# html only -> png
283+
# latex only -> pdf
284+
# all other cases, including html + latex -> png, pdf
285+
# For simplicity, we assume that the build targets appear in the command line.
286+
# We're falling back on using all formats in case that assumption fails.
287+
formats = {'html': ('png', 100), 'latex': ('pdf', 100)}
288+
plot_formats = [formats[target] for target in ['html', 'latex']
289+
if target in sys.argv] or list(formats.values())
290+
282291

283292
# GitHub extension
284293

@@ -537,30 +546,13 @@ def matplotlib_reduced_latex_scraper(block, block_vars, gallery_conf,
537546
# graphviz_output_format = 'svg'
538547

539548

540-
def reduce_plot_formats(app):
541-
# Fox CI and local builds, we don't need all the default plot formats, so
542-
# only generate the directly useful one for the current builder.
543-
if app.builder.name == 'html':
544-
keep = 'png'
545-
elif app.builder.name == 'latex':
546-
keep = 'pdf'
547-
else:
548-
return
549-
app.config.plot_formats = [entry
550-
for entry in app.config.plot_formats
551-
if entry[0] == keep]
552-
553-
554549
def setup(app):
555550
if any(st in version for st in ('post', 'alpha', 'beta')):
556551
bld_type = 'dev'
557552
else:
558553
bld_type = 'rel'
559554
app.add_config_value('releaselevel', bld_type, 'env')
560555

561-
if not is_release_build:
562-
app.connect('builder-inited', reduce_plot_formats)
563-
564556
# -----------------------------------------------------------------------------
565557
# Source code links
566558
# -----------------------------------------------------------------------------

0 commit comments

Comments
 (0)