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

Skip to content

Implement Sphinx-Gallery's make html-noplot #23870

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Sep 19, 2022

Conversation

rcomer
Copy link
Member

@rcomer rcomer commented Sep 11, 2022

PR Summary

Adds an html-noplot option to the Makefile, following the Sphinx-Gallery documentation. With this option the gallery structure is still generated, but we do not get the gallery images. On my laptop this option takes about a third of the time it takes to run make html. I think this would be useful for contributors who want to check other aspects of the documentation besides the gallery.

This option does trigger a lot of warnings, where various rst files link to the gallery images, so I'm not sure whether it makes sense to include the SPHINXOPTS variable used in the other options. I have for now.

The change to conf.py follows advice at sphinx-gallery/sphinx-gallery#913 (comment).

PR Checklist

Tests and Styling

  • Has pytest style unit tests (and pytest passes).
  • Is Flake 8 compliant (install flake8-docstrings and run flake8 --docstring-convention=all).

Documentation

  • New features are documented, with examples if plot related.
  • New features have an entry in doc/users/next_whats_new/ (follow instructions in README.rst there).
  • API changes documented in doc/api/next_api_changes/ (follow instructions in README.rst there).
  • Documentation is sphinx and numpydoc compliant (the docs should build without error).

@tacaswell tacaswell added this to the v3.7.0 milestone Sep 11, 2022
@tacaswell
Copy link
Member

The speed up is good, the warnings are not. We run with "warnings are errors" because if you do not then we will eventually accumulate a huge backlog of warnings (most of which are things like broken cross references or otherwise broken rst).

The best thing would be if SG could detect what images it would make and then drop in a place holder...but I suspect that the only way to detect that is to run the examples which defeats the purpose.

Is it possible to use custom warning filters in this mode and only ignore warnings about cross references to the gallery files?

Copy link
Member

@story645 story645 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should

  • make O=-Dplot_gallery=0 html skips the gallery build.

be removed since it's replaced by html-noplot?

@rcomer rcomer force-pushed the skip-gallery-builds branch from 46331a2 to 55b3991 Compare September 11, 2022 19:18
@rcomer
Copy link
Member Author

rcomer commented Sep 11, 2022

I did a little digging...

The warnings about missing images are logging warnings from here and here. The second one's message does not include the path of the missing image. I do not know enough about logging to know if there is an easy way to filter them. But since the second one does not include the image path, we would not be able to filter the message to check for gallery files.

Sphinx does have a config option to suppress warnings. "image.not_readable" in this list will suppress the first warning but for all images rather than just the gallery. I can't see the second warning in the list. Note also that this option is marked as experimental.

So I'm not really sure where to go from here!

@story645
Copy link
Member

While the error filtering would be amazing, I think as is this is still an improvement over using -D plot_gallery=0 directly since it's less error prone. We also document how to not exit on warnings for folks who need to turn off that default.

@jklymak
Copy link
Member

jklymak commented Sep 11, 2022

Isn't it the case, though, that the Sphinx gallery pain is only felt once? Subsequent doc builds are substantially faster because SG doesnt rerun all the examples?

@story645
Copy link
Member

story645 commented Sep 12, 2022

Isn't it the case, though, that the Sphinx gallery pain is only felt once?

dunno, I always use the -D plot_gallery=0 argument (and don't have warnings error out), which means I always get this warning

WARNING: The config value `plot_gallery' has type `str', defaults to `bool'.

which is something this PR fixes according to the discussion on sphinx 913 that Ruth linked to.

PS. I'd find fixing that in itself super helpful since I totally wasn't sure I was using that flag correctly cause of that error message.

@tacaswell
Copy link
Member

How hard would it be to put a check in our conf.py that when a flag/env/etc is set it tells sphinx-gallery we have no files to process? I think that would also save us a lot of time on the back-reference generation.

From testing it takes like 7:30 to build the docs from scratch on my system and 1:40 to build them a second time.

Running with -O=-Dplot_gallery=0 it took about 3 minutes the first time and 1:33 the second so a majority but not all of the savings is from not running the gallery code.

When you said "A lot" I read "one per image in the gallery", but it is a much more tractable number. A very brute-force way to fix this is to write a script to generate a "This is not the plot you are looking for" or other similar place holder image and then copy it to all these places in the output.

At least for the whats_new entries, it also does not seem like the worst thing to have a duplicate copy of the code...it might even be advantageous so old whats new entries do not change when we update an example!

/home/tcaswell/source/p/matplotlib/matplotlib/doc/api/toolkits/axes_grid1.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/api/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_curvelinear_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/intermediate/constrainedlayout_guide.rst:: WARNING: image file not readable: _static/constrained_layout_1b.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/intermediate/constrainedlayout_guide.rst:: WARNING: image file not readable: _static/constrained_layout_2b.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/pyplots/images/sphx_glr_annotation_basic_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/pyplots/images/sphx_glr_annotation_polar_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_text_arrow_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/shapes_and_collections/images/sphx_glr_fancybox_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_explain_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_connectionstyle_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_fancyarrow_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple02_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple03_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple04_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_anchored_box04_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple_coord01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple_coord02_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_annotate_simple_coord03_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_connect_simple01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/subplots_axes_and_figures/images/sphx_glr_axes_zoom_effect_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/annotations.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_custom_boxstyle01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/mathtext.rst:: WARNING: image file not readable: gallery/pyplots/images/sphx_glr_pyplot_mathtext_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/text/usetex.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_tex_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_axesgrid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_axesgrid2_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_demo_axes_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_colorbar_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_scatter_hist_locatable_axes_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_parasite_simple_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_axisline4_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_parasite_simple2_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_anchored_artists_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_inset_locator_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_inset_locator_demo2_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_demo_axes_rgb_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_axes_divider1_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axes_grid.rst:: WARNING: image file not readable: gallery/axes_grid1/images/sphx_glr_simple_axes_divider3_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_floating_axis_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_simple_axisline3_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_simple_axisartist1_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_parasite_axes2_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_curvelinear_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_floating_axes_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_floating_axis_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_simple_axis_direction01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_axis_direction_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_axis_direction_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_simple_axis_direction03_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_ticklabel_alignment_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_simple_axis_pad_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/axisartist.rst:: WARNING: image file not readable: gallery/axisartist/images/sphx_glr_demo_curvelinear_grid_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_subplot3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_lines3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_scatter3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_wire3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_surface3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_trisurf3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_contour3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_contourf3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_polys3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_bars3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_quiver3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_2dcollections3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/tutorials/toolkits/mplot3d.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_text3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/faq/howto_faq.rst:: WARNING: image file not readable: gallery/pyplots/images/sphx_glr_align_ylabels_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.0.rst:: WARNING: image file not readable: gallery/userdemo/images/sphx_glr_demo_gridspec01_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.0.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_triplot_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.1.rst:: WARNING: image file not readable: gallery/specialty_plots/images/sphx_glr_sankey_rankine_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.1.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_legend_demo_004.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.1.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_offset_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.1.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_contourf3d_2_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.2.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_trisurf3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.2.rst:: WARNING: image file not readable: gallery/statistics/images/sphx_glr_boxplot_demo_003.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.2.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_plot_streamplot_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.2.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_tripcolor_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.2.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_contourf_hatching_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/showcase/images/sphx_glr_xkcd_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_tricontour3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/lines_bars_and_markers/images/sphx_glr_eventplot_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_tricontour_smooth_user_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/lines_bars_and_markers/images/sphx_glr_stackplot_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.3.rst:: WARNING: image file not readable: gallery/misc/images/sphx_glr_patheffect_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.4.rst:: WARNING: image file not readable: gallery/specialty_plots/images/sphx_glr_skewt_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.4.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_quiver3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.5.rst:: WARNING: image file not readable: tutorials/intermediate/images/sphx_glr_color_cycle_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.5.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_contour_corner_mask_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_1.5.rst:: WARNING: image file not readable: gallery/lines_bars_and_markers/images/sphx_glr_filled_step_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_2.1.0.rst:: WARNING: image file not readable: gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_002.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_2.1.0.rst:: WARNING: image file not readable: gallery/pie_and_polar_charts/images/sphx_glr_polar_scatter_003.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_2.1.0.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_voxels_numpy_logo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_2.1.0.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_legend_demo_004.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.4.0.rst:: WARNING: image file not readable: gallery/lines_bars_and_markers/images/sphx_glr_bar_label_demo_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.4.0.rst:: WARNING: image file not readable: gallery/misc/images/sphx_glr_tickedstroke_demo_002.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.4.0.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_text_rotation_relative_to_line_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.4.0.rst:: WARNING: image file not readable: gallery/text_labels_and_annotations/images/sphx_glr_mathtext_fontfamily_example_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.4.0.rst:: WARNING: image file not readable: gallery/mplot3d/images/sphx_glr_errorbar3d_001.png
/home/tcaswell/source/p/matplotlib/matplotlib/doc/users/prev_whats_new/whats_new_3.5.0.rst:: WARNING: image file not readable: gallery/images_contours_and_fields/images/sphx_glr_image_antialiasing_001.png

I'm not super stoked that we have recommended a way to build the docs that produces so many errors (it makes it harder to see the actual errors we need fixed) and am pretty 👎🏻 on adding a make target that we know is going to fail. As noted above, just absorbing the one-time cost of building the examples is not terrible (we should document that!) and I think there are a number of ways to squash these warnings.

@timhoffm
Copy link
Member

timhoffm commented Sep 12, 2022

This all feels like workarounds, but may still be a thing we want to do short-term.

Long-term I see other ways to increase doc build speed.

  • Make sphinx-gallery faster by parallelization Multiprocesor support? sphinx-gallery/sphinx-gallery#25
  • There are a few very slow gallery examples, notably animations. Maybe we can have a special look at those and see if they can be speed up.
  • Make everything faster by improving matplotlib speed - i think we're still quite slow. Part of that is the clear and tick mechanisms, but likely we should do a thorough investigation. Changes here are a larger task but benefit the whole library. Would this be something for a small dev grant?

@rcomer
Copy link
Member Author

rcomer commented Sep 13, 2022

It turns out that SG will automatically create dummy images for you, but you need a comment in each example file telling it how many images to create.

So I went through and added enough comments to satisfy all the existing links. In a separate commit for now, so it's easy to revert if needed...

@rcomer
Copy link
Member Author

rcomer commented Sep 14, 2022

If we wanted to really nail it down, we could have a test that searches through the rst files to find the figure links and checks the required comments are in the relevant examples. Maybe here: https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/tests/test_doc.py

@timhoffm
Copy link
Member

I'm not super happy that we have to manually track the number of images. And then write a test so that we don't get it wrong. This does not feel right.

Can we/sg do better? To summarize the issue:

  1. By default, plot_gallery=0 does not create the figures to save time.
  2. This is ok, as far as the examples themselves are concerned.
  3. But if other code references the example image, that will raise a warning in sphinx.
  4. Since we turn doc warnings into errors, everything blows up.
  5. By setting sphinx_gallery_dummy_images=2 we can tell SG to copy a dummy image so that sphinx is happy.

The best solution would be to prevent the warnings in 3), as suggested by @tacaswell.

And @rcomer's inspires a possible fix:

The warnings about missing images are logging warnings from here and here. The second one's message does not include the path of the missing image. I do not know enough about logging to know if there is an easy way to filter them. But since the second one does not include the image path, we would not be able to filter the message to check for gallery files.

Sphinx does have a config option to suppress warnings. "image.not_readable" in this list will suppress the first warning but for all images rather than just the gallery. I can't see the second warning in the list. Note also that this option is marked as experimental.

This is a great insight. I agree that the "image.not_readable" config is not specific enough.

If we are adventurous this might work: We get hold of the above mentioned logger and add a filter that filters out missing image warnings on the images in our gallery directories.

@jklymak
Copy link
Member

jklymak commented Sep 14, 2022

I think if anyone is going to spend time doing something complex, it should be to parallelize the gallery build.

If someone really doesn't want to build the gallery, they should just do what @story645 does and run with plots turned off and error-on-warning turned off. However I don't think that should be the recommended way to build the docs (is that really what we are recommending?)

@story645
Copy link
Member

story645 commented Sep 15, 2022

is that really what we are recommending?

No, we just document it as an option. The reason I approved this PR in the first place is cause far as I could tell this was the sphinx-gallery replacement for that argument that gets rid of the confusing to me string/bool warning. I don't think providing the make recipe is necessarily recommending that folks use it either, it's just providing an existing option in a more user friendly way. We can always document something like `..Note: we do not recommend this because you may miss important warnings. You must turn off exit on warnings when using this" or we turn off exit on warnings as part of the make recipe.

ETA: So the reason I'm advocating documenting/including it even w/ a not recommended note is that there are folks on machines where the docs take a really long for them time to build and therefore they find this argument helpful and it's not a thing that I think is necessarily easily discoverable without knowing it exists.

@jklymak
Copy link
Member

jklymak commented Sep 15, 2022

Great - I'm not suggesting we can't list optional ways to build the docs, just that I wouldn't be happy to see our conf.py getting complicated to magically suppress warnings for an optimization that only has an effect on the first doc build.

From testing it takes like 7:30 to build the docs from scratch on my system and 1:40 to build them a second time.

Really? That is super fast - my machine must be pretty slow to run python!

@timhoffm
Copy link
Member

timhoffm commented Sep 15, 2022

Great - I'm not suggesting we can't list optional ways to build the docs, just that I wouldn't be happy to see our conf.py getting complicated to magically suppress warnings for an optimization that only has an effect on the first doc build.

I think it’s far less complicated than the discussion here may suggest. A hand full of lines should do.

and if that works we can upstream the code to Sphinx gallery. I mean, logically this is what should happen: in this mode, sg does not provide images. Since this is intentional we don’t want warnings for the missing images. It should be the task of sg to prevent these. Currently, they do it via the dummy crutch, but I think filtering is better (simpler/faster/more user friendly).

From testing it takes like 7:30 to build the docs from scratch on my system and 1:40 to build them a second time.

Really? That is super fast - my machine must be pretty slow to run python!

Maybe, but you could try a fresh setup of your dev environment. In my case that brought 50% speed up. Not exactly sure why, but I suppose some lib have improved.

@tacaswell
Copy link
Member

Really? That is super fast - my machine must be pretty slow to run python!

I have a pretty new machine (12th gen i7 with a nvme drive (I have in the past benchmarked this and I/O was a surprisingly big part of this...for a while I did silly things like try to build the docs on a ramdisk...)).

I also ran that with py311 which has some decent speed improvements (there has been a lot of work upstream making CPython faster).

@rcomer rcomer force-pushed the skip-gallery-builds branch from c3d1a35 to 1374e34 Compare September 18, 2022 20:44
@rcomer
Copy link
Member Author

rcomer commented Sep 18, 2022

Thanks all for your thoughts. Following @timhoffm's suggestion I have added a filter in conf.py.

@story645 So the reason I'm advocating documenting/including it even w/ a not recommended note is that there are folks on machines where the docs take a really long for them time to build and therefore they find this argument helpful and it's not a thing that I think is necessarily easily discoverable without knowing it exists.

Full disclosure: I am doing this on an 11-year-old laptop and it takes over half an hour to build the full docs. It could be argued that it's my own silly fault for trying to do that in the first place! I don't think I ever looked at the "how to build the docs" section of the dev guide until this PR - just saw that there was a Makefile and assumed I already knew how to use it. I am used to using the html-noplot option in another project (also options to skip the api build, but those are more bespoke) .

@story645
Copy link
Member

I am doing this on an 11-year-old laptop and it takes over half an hour to build the full docs. It could be argued that it's my own silly fault for trying to do that in the first place

Absolutely not! It takes about 20+ minutes on my 5? year old machine and I'm not building many backend or any of the font specific examples. That's why I use the flag! And the not building api sounds 👀 'cause I think my machine spends like 10 minutes there.

@timhoffm timhoffm merged commit 89d625e into matplotlib:main Sep 19, 2022
@timhoffm
Copy link
Member

Thanks a lot @rcomer! This is a great addition. Doc build times are a nuisance and I assume they are discouraging people from working on the docs. Anythinhg we can do to improve that is a win.

@rcomer
Copy link
Member Author

rcomer commented Sep 21, 2022

I have opened sphinx-gallery/sphinx-gallery#1006 to see if Sphinx-Gallery want to include the filter a their level.

timhoffm added a commit to timhoffm/matplotlib that referenced this pull request Nov 1, 2022
The make option `-Dplot_gallery=0` is superseeded by
`make html-noplot`. While we have removed it from the simple
calls (matplotlib#23870), it was still present in examples with multiple
options.
Remove it here and replace it by a still used option.
melissawm pushed a commit to melissawm/matplotlib that referenced this pull request Dec 19, 2022
The make option `-Dplot_gallery=0` is superseeded by
`make html-noplot`. While we have removed it from the simple
calls (matplotlib#23870), it was still present in examples with multiple
options.
Remove it here and replace it by a still used option.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants