Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.1k
Derive new_figure_manager from FigureCanvas.new_manager.#23090
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Conversation
timhoffm left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
For backcompat, the old codepath is maintained (and has priority).
In the long run (some years) we don't want to have two code paths. We should explicitly discourage the old way. But maybe that should be done whenshow() anddraw_if_interactive()are there as well.
This should be documented somewhere. Do we have technical documentation how a backend works?
Uh oh!
There was an error while loading.Please reload this page.
anntzer commentedMay 21, 2022
My plan was to first make all the changes, and then only document the full new API. I don't really think there's a reference doc of what an old-style backend must provide (closest is probably backend_template) and the point of this series of PR was also to make that documentation easier to write. I decided to start putting in these compat layers to show a bit the concrete end point before putting in more machinery for show and draw_if_interactive. Also note that there's actually a third way to define backends currently, namely via the |
timhoffm left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Is it possible to test the logic?
anntzer commentedMay 22, 2022
Sure, found a way to do it which is a bit hacky, but heh... |
333cead tofb33c71Compare
jklymak left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
This seems fine to me, but maybe should get a double check from@tacaswell ?
jklymak commentedMay 22, 2022
BTW, seems if there will be a few of these they should get some label. I made one, but feel free to replace with something more appropriate or rename |
lib/matplotlib/pyplot.py Outdated
| draw_if_interactive=getattr(backend_mod,"draw_if_interactive",None) | ||
| show=getattr(backend_mod,"show",None) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
| draw_if_interactive=getattr(backend_mod,"draw_if_interactive",None) | |
| show=getattr(backend_mod,"show",None) | |
| #draw_if_interactive = getattr(backend_mod, "draw_if_interactive", None) | |
| #show = getattr(backend_mod, "show", None) |
These are not used yet so I would prefer to not define them yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others.Learn more.
Sure.
tacaswell commentedMay 22, 2022
Sorry, that is my fault.
I thought we were going for "A backend is a |
Followup to the introduction of FigureCanvas.new_manager: allow backendmodules to not define new_figure_manager anymore, in which case wederive the needed function from FigureCanvas.new_manager. (In thefuture, I plan to do the same with draw_if_interactive and show, so that"a backend is just a module with a FigureCanvas class"; the advantage isthat the FigureCanvas subclass provided by the module can inheritmethods as needed from the parent class.)For backcompat, the old codepath is maintained (and has priority).To test this, manually alter backend_bases._Backend.export and removethe new_figure_manager entry from the exported functions, which deletesthat global function from all of the builtin methods (actually, we'llneed a deprecation cycle), and check that pyplot still works fine. Alsotweak the testing machinery to restore the original backend even if thebackend was not switched via a pytest marker.
anntzer commentedMay 22, 2022
No worries, we'll figure something out...
In practice you need to support the first form, so if what you actually have is just the class, you can just pass |
Uh oh!
There was an error while loading.Please reload this page.
Followup to the introduction of FigureCanvas.new_manager (#22925): allow backend
modules to not define new_figure_manager anymore, in which case we
derive the needed function from FigureCanvas.new_manager. (In the
future, I plan to do the same with draw_if_interactive and show, so that
"a backend is just a module with a FigureCanvas class"; the advantage is
that the FigureCanvas subclass provided by the module can inherit
methods as needed from the parent class.)
For backcompat, the old codepath is maintained (and has priority).
To test this, manually alter backend_bases._Backend.export and remove
the new_figure_manager entry from the exported functions, which deletes
that global function from all of the builtin methods (actually, we'll
need a deprecation cycle), and check that pyplot still works fine. Also
tweak the testing machinery to restore the original backend even if the
backend was not switched via a pytest marker.
PR Summary
PR Checklist
Tests and Styling
pytestpasses).flake8-docstringsand runflake8 --docstring-convention=all).Documentation
doc/users/next_whats_new/(follow instructions in README.rst there).doc/api/next_api_changes/(follow instructions in README.rst there).