Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

Merged
merged 4 commits into from
Mar 7, 2016
Merged

Bring back the module level 'backend' #6095

merged 4 commits into from
Mar 7, 2016

Conversation

ericdill
Copy link
Contributor

@ericdill ericdill commented Mar 2, 2016

The removal of the module level 'backend' broke ipython's pylab code. @tacaswell can you have a look? Renamed the pylab_setup() kwarg to name, so that backend could be a global in this function.

Closes #6092

The removal of the module level 'backend' broke ipython's pylab code.
This is the first attempt to bring it back.
@ericdill
Copy link
Contributor Author

ericdill commented Mar 2, 2016

It is not entirely clear to me how to keep the module level backend in sync with what is going on inside of pylab_setup().


'''
# Import the requested backend into a generic module object
if backend is None:
backend = matplotlib.get_backend() # validates, to match all_backends
Copy link
Member

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.

Copy link
Contributor Author

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:
Copy link
Member

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).

Copy link
Contributor Author

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?

Copy link
Member

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Alright. Done.

@tacaswell tacaswell added this to the 2.1 (next point release) milestone Mar 2, 2016
@tacaswell
Copy link
Member

Someone who is not me should look at this before it gets merged.

mdboom added a commit that referenced this pull request Mar 7, 2016
Bring back the module level 'backend'
@mdboom mdboom merged commit 0d1422b into matplotlib:master Mar 7, 2016
@ericdill ericdill deleted the module-level-backend branch March 8, 2016 18:28
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

Successfully merging this pull request may close these issues.

3 participants