-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
[Bug]: Plot directive clutters the output directory with unneeded files #24005
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
Comments
I think, this is somewhat related to #20814, in which a similar situation with source scripts was addressed. I've tried similarly to wrap the preceding image-copying code with But then I've discovered that the overall logic of copying all these files is seriously flawed. Namely, if adding links to images (and scripts) is not disabled, and different builds are done in succession (for example, So either the file-copying code needs to be moved somewhere else, or, if possible, file handling should be delegated to Sphinx itself... @harupy, @tacaswell and @QuLogic, maybe you can take a closer look at this? Because it also affects #20814. I'm not saying that the PR broke anything, since the lack of needed copying was apparently present before, but this issue is more or less related, and you already have some familiarity with the involved code and use cases. |
A simple method to delegate all file handling to Sphinx would be to use the
Does anybody know whether Sphinx provides any relevant API to solve this in a cleaner and more backward-compatible way? |
Yet another case of broken behavior of the current implementation is that links to files corresponding to documents in subdirectories of the source tree are generated incorrectly in the |
Issue #13858 seems to be very similar in terms of incorrect generated links, but for the |
I think I have the same problem, with the difference that in my case I am asking both to show the source code link and downloadable images (but I could do without that to be honest) I have an
This creates a new Interestingly, if we follow the instructions from this page this behaviour doesn't happen (but this forces the developer to keep source code into the docs folder). This is my work tree after generating the docs, |
Do your PRs relate to my case? |
@HealthyPear, I was able to model your case and can reproduce similar behavior. I suppose that your
My PR #24205 correctly treats the second part — it does copy all the necessary files into It, however, doesn't modify the caching part, so you'll still see
to
Then the cached files will end up in |
Ok good.
I think there is an easier cross-platform solution for this part, since the
|
By the way, my fina plan is actually to make a sort of gallery from my examples, just like matplotlob has.
Isn't this what they are doing here, though? |
Bug summary
Using the Matplotlib plot directive in Sphinx documentation results in cluttering the output directory with all the produced image files in all generated formats even when they are not needed (
plot_html_show_formats = False
). This is especially obvious with thesinglehtml
builder, where all the necessary images must be inside the_images
subdirectory, but in fact, in addition to_images
, the whole directory tree with every image in every format is copied to the output directory, although nothing of it is referenced from the HTML file.What is more interesting, if another builder is executed first, then its cached images are reused properly — only the necessary files are copied into
_images
, without cluttering the output directory with unneeded files and subdirectories.Code for reproduction
See a minimal working example at https://github.com/MikhailRyazanov/plot-clutter.
Actual outcome
From step 1 of the example above:
Expected outcome
From step 2 of the example above:
Additional information
In practice, this undesired behavior directly affects the downloadable documentation at Read the docs — see issue #9068 there.
Operating system
No response
Matplotlib Version
3.5.2
Matplotlib Backend
No response
Python version
No response
Jupyter version
No response
Installation
Linux package manager
The text was updated successfully, but these errors were encountered: