Skip to content

backend_driver.py overhaul #8069

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
wants to merge 9 commits into from
Closed

Conversation

dstansby
Copy link
Member

Whilst doing some documentation changes, I noticed backend_driver.py is very out of date. Annoyingly each example has to be explicitly set in the file for it to be tested. This PR updates backend_driver.py to:

  • Automatically discover every example file
  • Correctly strip plt.show calls etc.

In the future this file might be a way provide a good way of benchmarking (#2188) by timing how long all the examples take to run.

@QuLogic
Copy link
Member

QuLogic commented Feb 12, 2017

Given how you keep hitting this file in your docathon PRs, I think we should merge this sooner rather than later.

@dstansby
Copy link
Member Author

Okay, I think this is almost good to go. The only thing I have left to do is to actually run this on a variety of backends and update the files to exclude. If anyone else wants a go, feel free to push to my branch with files to exclude.

@QuLogic
Copy link
Member

QuLogic commented Feb 26, 2017

Is this complete? Do you want to rebase and squash a bit? There are a quite a few commits for just one file change. In any case, a rebase is needed because of the conflicts.

@dstansby
Copy link
Member Author

I think this is almost done, I'll give it a squash/rebase/check sometime soon.

@dstansby dstansby added this to the 2.2 (next next feature release) milestone Mar 1, 2017
@dstansby
Copy link
Member Author

There's a big ol' squash, I will test this on Agg at some point soon, and if it all works I think this is good to merge (after a couple of reviews).

Testing on other backends can probably then be added a 'new contributor friendly' issue.

@dstansby dstansby self-assigned this Mar 13, 2017
@dstansby
Copy link
Member Author

dstansby commented Mar 14, 2017

Right, this is now working fully on Agg. How do people feel about merging this now?

Current todo, which I think could each be opened as new-contributor-friendly issues:

  • Run on each of the other backends and check that all the examples work
  • Re-factor so running the script works if not in the examples/tests directory
  • Output the results to a csv file instead of just printing them to the terminal

@dstansby dstansby changed the title [WIP] backend_driver.py overhaul backend_driver.py overhaul Mar 14, 2017
@dstansby dstansby modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Mar 14, 2017
Copy link
Member

@QuLogic QuLogic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM otherwise.

@NelleV
Copy link
Member

NelleV commented Mar 16, 2017

This file should probably be moved to the tools folder.

@dstansby
Copy link
Member Author

@NelleV would you mind if I added that move to "Re-factor so running the script works if not in the examples/tests directory"? It seems a logical thing to do at the same time.

@dstansby dstansby removed their assignment Mar 17, 2017
@QuLogic
Copy link
Member

QuLogic commented Mar 17, 2017

Are you referring to a different PR?

@dstansby
Copy link
Member Author

Sorry, I'm referring to my mini todo list here in my above comment #8069 (comment)

@tacaswell tacaswell modified the milestones: 2.1 (next point release), 2.2 (next next feature release) Aug 29, 2017
@dstansby
Copy link
Member Author

dstansby commented Oct 9, 2017

I have rebased this on to current master if anyone wants to take it for a spin.

@tacaswell
Copy link
Member

Current output:

Some of these are because the existing __future__ import is split across 2 lines. Might be worth just dropping that logic and trusting that the examples have the proper __future__ imports they need?

Backend agg took 5.23 minutes to complete
  Failures: 
     '../misc/rc_traits_sgskip.py'
     '../misc/svg_filter_line.py'
     '../misc/print_stdout_sgskip.py'
     '../misc/rasterization_demo.py'
     '../misc/agg_buffer.py'
     '../misc/svg_filter_pie.py'
     '../misc/multiprocess_sgskip.py'
     '../userdemo/pgf_preamble_sgskip.py'
     '../text_labels_and_annotations/legend_demo.py'
     '../animation/movie_demo_sgskip.py'
        template ratio 1.127, template residual 0.591
Backend ps took 4.55 minutes to complete
  Failures: 
     '../misc/agg_buffer_to_array.py'
     '../misc/rc_traits_sgskip.py'
     '../misc/svg_filter_line.py'
     '../misc/print_stdout_sgskip.py'
     '../misc/rasterization_demo.py'
     '../misc/agg_buffer.py'
     '../misc/svg_filter_pie.py'
     '../misc/multiprocess_sgskip.py'
     '../userdemo/pgf_preamble_sgskip.py'
     '../text_labels_and_annotations/rainbow_text.py'
     '../text_labels_and_annotations/legend_demo.py'
     '../animation/movie_demo_sgskip.py'
        template ratio 0.979, template residual -0.097
Backend svg took 5.25 minutes to complete
  Failures: 
     '../misc/agg_buffer_to_array.py'
     '../misc/rc_traits_sgskip.py'
     '../misc/svg_filter_line.py'
     '../misc/print_stdout_sgskip.py'
     '../misc/rasterization_demo.py'
     '../misc/agg_buffer.py'
     '../misc/svg_filter_pie.py'
     '../misc/multiprocess_sgskip.py'
     '../userdemo/pgf_preamble_sgskip.py'
     '../text_labels_and_annotations/rainbow_text.py'
     '../text_labels_and_annotations/legend_demo.py'
     '../animation/movie_demo_sgskip.py'
        template ratio 1.130, template residual 0.604
Backend pdf took 4.85 minutes to complete
  Failures: 
     '../misc/agg_buffer_to_array.py'
     '../misc/rc_traits_sgskip.py'
     '../misc/svg_filter_line.py'
     '../misc/print_stdout_sgskip.py'
     '../misc/rasterization_demo.py'
     '../misc/agg_buffer.py'
     '../misc/svg_filter_pie.py'
     '../misc/multiprocess_sgskip.py'
     '../userdemo/pgf_preamble_sgskip.py'
     '../text_labels_and_annotations/rainbow_text.py'
     '../text_labels_and_annotations/legend_demo.py'
     '../animation/movie_demo_sgskip.py'
        template ratio 1.045, template residual 0.210
Backend template took 4.64 minutes to complete
  Failures: 
     '../images_contours_and_fields/quadmesh_demo.py'
     '../misc/agg_buffer_to_array.py'
     '../misc/rc_traits_sgskip.py'
     '../misc/svg_filter_line.py'
     '../misc/print_stdout_sgskip.py'
     '../misc/demo_agg_filter.py'
     '../misc/rasterization_demo.py'
     '../misc/patheffect_demo.py'
     '../misc/agg_buffer.py'
     '../misc/svg_filter_pie.py'
     '../misc/multiprocess_sgskip.py'
     '../mplot3d/wire3d_animation.py'
     '../mplot3d/rotate_axes3d.py'
     '../showcase/xkcd.py'
     '../userdemo/pgf_preamble_sgskip.py'
     '../text_labels_and_annotations/rainbow_text.py'
     '../text_labels_and_annotations/usetex_fonteffects.py'
     '../text_labels_and_annotations/tex_demo.py'
     '../text_labels_and_annotations/usetex_demo.py'
     '../text_labels_and_annotations/legend_demo.py'
     '../text_labels_and_annotations/usetex_baseline_test.py'
     '../axes_grid1/demo_axes_grid2.py'
     '../animation/movie_demo_sgskip.py'
     '../animation/animation_demo.py'
        template ratio 1.000, template residual 0.000

@anntzer
Copy link
Contributor

anntzer commented Oct 22, 2017

I would just run the file as it is, without trying to play with stripped lines. sys.path can by set by PYTHONPATH and the backend can be set by MPLBACKEND (and if the backend is Agg, then plt.show() is already a noop). If we worry about spurious savefigs (which we probably should indeed, we should just move to a tmpdir before running the examples (and we can append importing savefig and calling savefig). Examples that need to call np.seterr should do so themselves.

Edit: I was worried this would fail if the example explicitly wanted to set a backend itself but it looks like it can actually do that:

$ MPLBACKEND=Agg python -c 'import matplotlib as m; m.use("qt5agg")'

works.

Copy link
Member

@tacaswell tacaswell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe rethink how we handle the imports and removing show.

@tacaswell tacaswell modified the milestones: v2.1.1, v2.2 Oct 30, 2017
@tacaswell
Copy link
Member

punting to 2.2

@dstansby
Copy link
Member Author

Attempting to revive this, so I've rebased. I think it's really quite a useful thing to be able to check all the examples run properly.

dstansby and others added 8 commits July 18, 2019 14:18
Remove old pylab option

Do plt. search for lines to strip

PEP8

Print fname if excluding

Use pylab_examples as default directory

Create file and directory list in same loop

Add docstring to end of --help

Remove reporting of missing tests

By default test all discovered files

Don't test user interface examples

Properly exclued excluded files

Clean up configuration of files to not run

dict formatting

backend_driver fixes

Use argparser

Use argparse better

Revert wrong changes

Remove redundant elif
These are demos that require user interaction
Copy link
Member

@timhoffm timhoffm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cleanup itself looks technically good (and it's not critical anyway as this is not part of the shipped library).

I'm wondering though, how realistic this is when we leave out the rendering. Would it make sense to always use savefig? OTOH, this feels like a reimplementation of sphinx-gallery. Can't we use just that for testing?

@dstansby
Copy link
Member Author

That's a good point, this PR is so old that it pre-dates sphinx-gallery (at least used by us). Maybe it is obsolete now. On the other hand, probably no harm in merging this and making the script useable (as you say).

@QuLogic
Copy link
Member

QuLogic commented Jun 20, 2020

Replaced by #17226.

@QuLogic QuLogic closed this Jun 20, 2020
@dstansby
Copy link
Member Author

🎉 happy that this (or a variant on it) finally ended up being merged!

@dstansby dstansby deleted the backend-driver branch June 20, 2020 09:23
@story645 story645 removed this from the future releases milestone Oct 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants