Matplotlib plot directive in some cases copies unnecessary files to the output directory, and in some cases the necessary files are not copied. This is a minimal working example for issue #24005.
Steps to reproduce:
-
Stray files in a “clean” build:
a. Run
make clean, just in case, to ensure a clean build. b. Runmake singleghtmlto produce a “single HTML” build. c. Inspect the output directorybuild/singleghtml— in addition to the necessary fileindex.htmland the_staticand_imagesdirectories (the latter contains all the necessary images used inindex.html), there are also absolutely unnecessary and unreferenced SVG and PDF files directly and inside the absolutely unnecessary and unreferenced subdirectorysubdir. -
No stray files when reusing another build:
a. Run
make cleanto clean the previous build results. b. Runmake htmlto produce a regular “HTML” build inbuild/html. The output also has the same unnecessary and unreferenced files, as above, but this is not the point. c. Runmake singleghtmlto produce a “single HTML” build, which will reuse the images already produced by the previous build. d. Inspect the output directorybuild/singleghtml— now it looks as expected, without any unnecessary and unreferenced SVG and PDF files and subdirectories (all used images are properly inside_images). -
Needed files are not copied when reusing another build:
a. Comment out
plot_html_show_formats = False(andplot_html_show_source_link = False) inconf.pyto enable automatic links to image formats (and plotting scripts). b. Runmake cleanto clean the previous build results. c. Runmake htmlto produce a regular “HTML” build inbuild/html. The output has all the necessary files that are linked from the HTML, as expected. d. Runmake singleghtmlto produce a “single HTML” build, which will reuse the images (and scripts) already produced by the previous build. e. Inspect the output directorybuild/singleghtml— it doesn't have any image (and script) files, resulting in broken links to “(Source code, svg, pdf)” for all the plots in the HTML file. -
Links with wrong subdirectory paths in
singleghtmlbuild:a. Use the modified
conf.pyfrom the previous build. b. Runmake cleanto clean the previous build results. c. Runmake singleghtmlto produce a “single HTML” build, which should include links to scripts and image formats. d. Inspect the output directory and confirm thatbuild/singleghtml/subdircontains{other-1,script}.{py,pdf,svg}files. e. Open the generated HTML filebuild/singleghtml/index.htmland try using the “(Source code, svg, pdf)” links in the “Other” section. None of them works because they all refer to../subdir/<file>(resolving tobuild/subdir/<file>) instead ofsubdir/<file>(correct path relative toindex.html, resolving tobuild/singleghtml/subdir/<file>).