2222from datetime import datetime
2323import time
2424
25+ # Release mode enables optimizations and other related options.
26+ is_release_build = tags .has ('release' ) # noqa
27+
2528# are we running circle CI?
2629CIRCLECI = 'CIRCLECI' in os .environ
2730
@@ -88,6 +91,7 @@ def _check_dependencies():
8891 "matplotlib" : 'matplotlib' ,
8992 "numpydoc" : 'numpydoc' ,
9093 "PIL.Image" : 'pillow' ,
94+ "pydata_sphinx_theme" : 'pydata_sphinx_theme' ,
9195 "sphinx_copybutton" : 'sphinx_copybutton' ,
9296 "sphinx_gallery" : 'sphinx_gallery' ,
9397 "sphinxcontrib.inkscapeconverter" : 'sphinxcontrib-svg2pdfconverter' ,
@@ -175,10 +179,10 @@ def _check_dependencies():
175179 'remove_config_comments' : True ,
176180 'min_reported_time' : 1 ,
177181 'thumbnail_size' : (320 , 224 ),
178- 'compress_images' : () if CIRCLECI else ('thumbnails' , 'images' ),
182+ # Compression is a significant effort that we skip for local and CI builds.
183+ 'compress_images' : ('thumbnails' , 'images' ) if is_release_build else (),
179184 'matplotlib_animations' : True ,
180- # 3.7 CI doc build should not use hidpi images during the testing phase
181- 'image_srcset' : [] if sys .version_info [:2 ] == (3 , 7 ) else ["2x" ],
185+ 'image_srcset' : ["2x" ],
182186 'junit' : '../test-results/sphinx-gallery/junit.xml' if CIRCLECI else '' ,
183187}
184188
@@ -293,7 +297,9 @@ def _check_dependencies():
293297html_logo = "_static/logo2.svg"
294298html_theme_options = {
295299 "logo_link" : "index" ,
296- "collapse_navigation" : True if CIRCLECI else False ,
300+ # collapse_navigation in pydata-sphinx-theme is slow, so skipped for local
301+ # and CI builds https://github.com/pydata/pydata-sphinx-theme/pull/386
302+ "collapse_navigation" : not is_release_build ,
297303 "icon_links" : [
298304 {
299305 "name" : "gitter" ,
@@ -319,7 +325,7 @@ def _check_dependencies():
319325 "show_prev_next" : False ,
320326 "navbar_center" : ["mpl_nav_bar.html" ],
321327}
322- include_analytics = False
328+ include_analytics = is_release_build
323329if include_analytics :
324330 html_theme_options ["google_analytics_id" ] = "UA-55954603-1"
325331
@@ -538,13 +544,30 @@ def _check_dependencies():
538544# graphviz_output_format = 'svg'
539545
540546
547+ def reduce_plot_formats (app ):
548+ # Fox CI and local builds, we don't need all the default plot formats, so
549+ # only generate the directly useful one for the current builder.
550+ if app .builder .name == 'html' :
551+ keep = 'png'
552+ elif app .builder .name == 'latex' :
553+ keep = 'pdf'
554+ else :
555+ return
556+ app .config .plot_formats = [entry
557+ for entry in app .config .plot_formats
558+ if entry [0 ] == keep ]
559+
560+
541561def setup (app ):
542562 if any (st in version for st in ('post' , 'alpha' , 'beta' )):
543563 bld_type = 'dev'
544564 else :
545565 bld_type = 'rel'
546566 app .add_config_value ('releaselevel' , bld_type , 'env' )
547567
568+ if not is_release_build :
569+ app .connect ('builder-inited' , reduce_plot_formats )
570+
548571# -----------------------------------------------------------------------------
549572# Source code links
550573# -----------------------------------------------------------------------------
0 commit comments