| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
|
👍 in principle, but the docs need to build cleanly! |
Sorry, something went wrong.
| try: | ||
| figman.canvas.figure.savefig(img.filename(format), dpi=dpi) | ||
| if config.plot_preserve_dir and outname: | ||
| print("Preserving '{0}' into '{1}'".format(img.filename(format), config.plot_preserve_dir)) |
There was a problem hiding this comment.
Not reviewing, but I don't think you want print in here do you? I'd do _log.info or _log.debug?
Sorry, something went wrong.
There was a problem hiding this comment.
Yes, that's probably what I want, but I didn't know about them. I'll update.
Sorry, something went wrong.
There was a problem hiding this comment.
Actually, I don't see _log as a variable in the plot_directive.py namespace, so I'm not sure how to make that adjustment.
Sorry, something went wrong.
There was a problem hiding this comment.
If its not already in this module, then up at the top:
# ... other imports
import logging
# ... other imports
_log = logging.getLogger(__name__)
Sorry, something went wrong.
There was a problem hiding this comment.
Thanks: got that up.
Sorry, something went wrong.
|
Eliminated some spaces |
Sorry, something went wrong.
|
@r-barnes sorry this didn't get a second review yet. If you give it a rebase and ping me I'll give it a quick look and merge on the basis of @tacaswell 's approval. We are about to branch 3.2, so it'd be nice to get this in |
Sorry, something went wrong.
|
Wouldn't plot_preserve_dir better be named plot_cache_dir? |
Sorry, something went wrong.
| if config.plot_preserve_dir and outname: | ||
| outfiles = glob.glob(os.path.join(config.plot_preserve_dir, outname) + '*') | ||
| for of in outfiles: | ||
| _log.info("Copying preserved copy of '{0}' into '{1}'".format(of, build_dir)) |
There was a problem hiding this comment.
we are py36+ so we can use f-strings 😄
Sorry, something went wrong.
|
sorry, I read the year when this was opened wrong and thought it was from this January, not from 2 years ago. |
Sorry, something went wrong.
I did the re-base and added the leading spaces
There was a problem hiding this comment.
modulo tests passing
Sorry, something went wrong.
|
I took the liberty of pushing an update to fix the doc issues. |
Sorry, something went wrong.
There was a problem hiding this comment.
Needs a rebase on master. Then move whats new entry to our new whats new scheme.
Sorry, something went wrong.
| def render_figures(code, code_path, output_dir, output_base, context, | ||
| function_name, config, context_reset=False, | ||
| close_figs=False): | ||
| close_figs=False, outname=''): |
There was a problem hiding this comment.
Would go with outname=None, which is IMHO a more standard way for "not defined" than an empty string.
Sorry, something went wrong.
| @@ -0,0 +1,61 @@ | |||
| Plot Directive `outname` and `plot_preserve_dir` | |||
There was a problem hiding this comment.
I propose to rename plot_preserve_dir to plot_cache_dir.
Sorry, something went wrong.
|
See #25091 (comment) for context on closing. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
PR Summary
The Sphinx plot directive can be used to automagically generate figures for documentation like so:
.. plot:: import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np img = mpimg.imread('_static/stinkbug.png') imgplot = plt.imshow(img)But, if you reorder the figures in the documentation then all the figures may need to be rebuilt. This takes time. The names given to the figures are also fairly meaningless, making them more difficult to index by search engines or to find on a filesystem.
Alternatively, if you are compiling on a limited-resource service like ReadTheDocs, you may wish to build imagery locally to avoid hitting resource limits on the server. Using the new changes allows extensive dynamically generated imagery to be used on services like ReadTheDocs.
The :outname: property
These problems are addressed through two new features in the plot directive. The first is the introduction of the :outname: property. It is used like so:
.. plot:: :outname: stinkbug_plot import matplotlib.pyplot as plt import matplotlib.image as mpimg import numpy as np img = mpimg.imread('_static/stinkbug.png') imgplot = plt.imshow(img)Without :outname:, the figure generated above would normally be called, e.g. docfile3-4-01.png or something equally mysterious. With :outname: the figure generated will instead be named stinkbug_plot-01.png or even stinkbug_plot.png. This makes it easy to understand which output image is which and, more importantly, uniquely keys output images to code snippets.
The plot_preserve_dir configuration value
Setting the plot_preserve_dir configuration value to the name of a directory will cause all images with :outname: set to be copied to this directory upon generation.
If an image is already in plot_preserve_dir when documentation is being generated, this image is copied to the build directory thereby pre-empting generation and reducing computation time in low-resource environments.
Related issues were raised on ReadTheDocs (link) and on StackOverflow (link).
PR Checklist