Skip to content

Restore something like backend_driver #9284

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

Closed
tacaswell opened this issue Oct 5, 2017 · 6 comments
Closed

Restore something like backend_driver #9284

tacaswell opened this issue Oct 5, 2017 · 6 comments
Milestone

Comments

@tacaswell
Copy link
Member

It turns out that @cgohlke was using this to smoke test the windows wheels. We should provide an easy way to run all of the examples against the currently installed version of matplotlib and at least cycle through the Agg, svg, pdf, and one GUI backend.

Exact work:

  • write a script in tools to exercise all of the examples and tutorials (this may have to deal with examples that call show, probably by turing on plt.ion() and defensively calling plt.close('all'))
  • make the backend list configurable
  • bonus: regex matching on file names
@tacaswell tacaswell added new-contributor-friendly Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. labels Oct 5, 2017
@tacaswell tacaswell added this to the 2.1.1 (next bug fix release) milestone Oct 5, 2017
@anntzer
Copy link
Contributor

anntzer commented Oct 5, 2017

A funny (dunno how silly) way to achieve this would be to hack into sphinx-gallery. You basically need to

  1. force the backend while s_g still believes it's agg (it has a forced check on that).
  2. patch s_g.gen_rst.save_figures to instead close the figures.

Perhaps this can be done in the docs' conf.py when an environment variable is set...

@tacaswell
Copy link
Member Author

I have a slight preference for this to run without any of the docs requirements (as just building the docs covers 25% of the use case and likely 90% of the benefit).

@anntzer
Copy link
Contributor

anntzer commented Oct 5, 2017

FWIW the following works for non-interactive backends (for interactive backends you have the additional problem of how to send it a signal to close it...):

diff --git a/doc/conf.py b/doc/conf.py
index 818238642..764f68223 100644
--- a/doc/conf.py
+++ b/doc/conf.py
@@ -480,3 +480,31 @@ def skip_deprecated(app, what, name, obj, skip, options):
 
 def setup(app):
     app.connect('autodoc-skip-member', skip_deprecated)
+
+
+if "MPL_BACKEND_DRIVER" in os.environ:
+    backend, fmt = os.environ.get("MPL_BACKEND_DRIVER").split(":")
+    import shutil
+    for regen in ["examples", "gallery"]:
+        shutil.rmtree("examples", ignore_errors=True)  # force regen
+    matplotlib.use(backend)
+    from matplotlib import pyplot as plt
+    # Tricking s-g to believe we're using Agg...
+    _get_backend = matplotlib.get_backend
+    _use = matplotlib.use
+    matplotlib.get_backend = lambda: "agg"
+    matplotlib.use = lambda backend: None
+    from sphinx_gallery import gen_gallery, gen_rst
+    matplotlib.get_backend = _get_backend
+    matplotlib.use = _use
+    _generate_gallery_rst = gen_gallery.generate_gallery_rst
+    def generate_gallery_rst(app):
+        _generate_gallery_rst(app)
+        sys.exit(0)
+    gen_gallery.generate_gallery_rst = generate_gallery_rst
+    def save_figures(*args):
+        for fignum in plt.get_fignums():
+            from io import BytesIO
+            plt.figure(fignum).savefig(BytesIO(), format=fmt)
+        return "", 0
+    gen_rst.save_figures = save_figures

Run with MPL_BACKEND_DRIVER=agg:png ./make.py (or svg:svg, or pdf:pdf, etc.)

@QuLogic QuLogic changed the title Restore something like backend_diver Restore something like backend_driver Oct 5, 2017
@dstansby
Copy link
Member

dstansby commented Oct 6, 2017

cough I tried to do this a while back ;) #8069

Wouldn't be surprised if it's easier dumping backend_driver and starting from scratch though.

@tacaswell
Copy link
Member Author

@dstansby 🐑

@tacaswell tacaswell added Good first issue Open a pull request against these issues if there are no active ones! and removed Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. Good first issue Open a pull request against these issues if there are no active ones! new-contributor-friendly labels Oct 16, 2017
@tacaswell tacaswell modified the milestones: v2.1.1, v2.2 Oct 30, 2017
@anntzer
Copy link
Contributor

anntzer commented Sep 30, 2020

closed by #17226

@anntzer anntzer closed this as completed Sep 30, 2020
@QuLogic QuLogic modified the milestones: needs sorting, v3.3.0 Sep 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants