-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Bring back the module level 'backend' #6095
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
The removal of the module level 'backend' broke ipython's pylab code. This is the first attempt to bring it back.
It is not entirely clear to me how to keep the module level |
|
||
''' | ||
# Import the requested backend into a generic module object | ||
if backend is None: | ||
backend = matplotlib.get_backend() # validates, to match all_backends |
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.
calling matplotlib.get_backend()
in this function was the main point of the PR that broke this. In either case (passed in arg or calling get_backend
) the value just needs to be mirrored out to backend
. If we only needed to read this value we would not need global
as the function would correctly close over it.
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.
Ok, so if backend is None, use get_backend()
and set the module level backend to the result, then keep going with this function?
|
||
if backend.startswith('module://'): | ||
backend_name = backend[9:] | ||
if name is 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.
I think
global backend
if name is None:
name = mpl.get_backend()
backend = name
will do the right thing here. It will always defer to an explicitly passed input and then fall back to get_backend
which in the end just consults rcparams for the requested backend. Assigning to the variable marked global will change the object that the module-level attribute points at (with out the global it would just bind a local variable).
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 there any guarantee that name
, if not None, is anything sensible that you would want to set to backends.backend
? For example, say I do pylab_setup('keyboard')
. Obviously that's dumb since keyboard
is not a valid mpl backend. How should pylab_setup
handle this? I would imagine that you might want to do the global backend; backend=name
at the very end right before the return?
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.
That is a good idea.
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.
Alright. Done.
Someone who is not me should look at this before it gets merged. |
Bring back the module level 'backend'
The removal of the module level 'backend' broke ipython's pylab code. @tacaswell can you have a look? Renamed the
pylab_setup()
kwarg toname
, so thatbackend
could be a global in this function.Closes #6092