-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
TST: Backend switching API (don't merge) #11612
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
Conversation
See changes documented in the API changes file. Some followup cleanup (of the now unused old machinery) will come as a separate PR (left some "FIXME: Remove." comments). Changes to the build process (namely, getting rid of trying to detect the default backend in setupext.py) will come as a separate PR. I inlined pylab_setup into switch_backend (and deprecated the old version of pylab_setup) because otherwise the typical call stack would be `use()` -> `set rcParams['backend'] = ...` -> `switch_backend()` -> `pylab_setup()`, which is a bit of a mess; at least we can get rid of one of the layers.
The selection logic is now described in the module's docstring. The only changes is that the QT_ENV_MAJOR_VERSION global, which would sometimes be defined (depending on the state of the import cache, the QT_API environment variable, and the requested backend) is never defined anymore.
The I am 50/50 on adding Similarly, storing the current backend in matplotlib/lib/matplotlib/__init__.py Lines 1380 to 1382 in e3042ab
I think I am on board with pushing people to I am 👍 on adding |
The changes are rather independent and could be introduced incrementally, if we are not sure about some of them:
A reasonable minimal start for 3.0 could be just to do 1. (and maybe 4.) - acknowledging that the original PRs #11581 and #11600 are tagged 3.0 and release-critical. The other points seem to be more controversial and there is no need to rush it. |
try: | ||
switch_backend(candidate) | ||
except ImportError: | ||
continue |
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.
probably need to do something if no backend is successfully imported.
cbook.warn_deprecated('3.0', | ||
"The rcParam 'backend' is deprecated. Use the rcParam " | ||
"'default_backends' to access the defaults. Use get_backend() " | ||
"to get the current backend.") |
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.
But then you need to store the current backend somewhere else and update the implementation of get_backend accordingly.
@timhoffm I agree with your suggestions above. OTOH for now we want to get backend switching in, and the existing rcParam stuffing, while suboptimal, is the existing API. So for 3.0 I think we decided to move along w/ @anntzer PR (plus or minus any review changes) and then we can re-open the deprecation/API refinement for 3.1 (due December-ish). |
Superseeded by #11600 |
PR Summary
This PR creates a possible API for backend switching. The API is laid out in the last commit. Previous commits are from #11600 and only contain the actual switching logic.
The code is not fully tested. It's main purpose is to give an idea how the following API can be implemented:
rcParams['default_backends']
that accepts a list of possible backends to try out.rcParams['backend']
is deprecated.rcParams['backend'] is deprecated. Users should use
rcParams['default_backends']or
get_backend()` depeding on their needs.matplotlib.use()
is deprecated in favor ofset_backend()
-- this is independent of the other API changes but adds to consistency.Typical use-cases:
Setting the default backend
new API:
current API (deprecated):
Setting the current backend
new API:
current API (deprecated):
Querying the current backend:
new API:
current API (deprecated):