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 singleghtml
to produce a “single HTML” build. c. Inspect the output directorybuild/singleghtml
— in addition to the necessary fileindex.html
and the_static
and_images
directories (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 clean
to clean the previous build results. b. Runmake html
to 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 singleghtml
to 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.py
to enable automatic links to image formats (and plotting scripts). b. Runmake clean
to clean the previous build results. c. Runmake html
to produce a regular “HTML” build inbuild/html
. The output has all the necessary files that are linked from the HTML, as expected. d. Runmake singleghtml
to 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
singleghtml
build:a. Use the modified
conf.py
from the previous build. b. Runmake clean
to clean the previous build results. c. Runmake singleghtml
to produce a “single HTML” build, which should include links to scripts and image formats. d. Inspect the output directory and confirm thatbuild/singleghtml/subdir
contains{other-1,script}.{py,pdf,svg}
files. e. Open the generated HTML filebuild/singleghtml/index.html
and 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>
).