Bring back the module level 'backend' #6095

Merged
merged 4 commits into from Mar 7, 2016

Conversation

Projects
None yet
3 participants
Contributor

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

mdboom added the needs_review label Mar 2, 2016

@ericdill ericdill MNT: Bring back the module level 'backend'
The removal of the module level 'backend' broke ipython's pylab code.
This is the first attempt to bring it back.
397bfc7
Contributor

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

@tacaswell tacaswell commented on the diff Mar 2, 2016

lib/matplotlib/backends/__init__.py
'''
# Import the requested backend into a generic module object
- if backend is None:
- backend = matplotlib.get_backend() # validates, to match all_backends
@tacaswell

tacaswell Mar 2, 2016

Owner

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.

@ericdill

ericdill Mar 2, 2016

Contributor

Ok, so if backend is None, use get_backend() and set the module level backend to the result, then keep going with this function?

@ericdill ericdill MNT: Set the module level `backend` in pylab_setup
f118405

@tacaswell tacaswell commented on the diff Mar 2, 2016

lib/matplotlib/backends/__init__.py
'''
# Import the requested backend into a generic module object
- if backend is None:
- backend = matplotlib.get_backend() # validates, to match all_backends
-
- if backend.startswith('module://'):
- backend_name = backend[9:]
+ if name is None:
@tacaswell

tacaswell Mar 2, 2016

Owner

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

@ericdill

ericdill Mar 2, 2016

Contributor

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?

@tacaswell

tacaswell Mar 2, 2016

Owner

That is a good idea.

@ericdill

ericdill Mar 2, 2016

Contributor

Alright. Done.

@ericdill ericdill MNT: Set the module backend param at the end
f142835

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

@ericdill ericdill PEP8: Shorten lines that are too long
5a99151
Owner

tacaswell commented Mar 4, 2016

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

@mdboom mdboom added a commit that referenced this pull request Mar 7, 2016

@mdboom mdboom Merge pull request #6095 from ericdill/module-level-backend
Bring back the module level 'backend'
0d1422b

@mdboom mdboom merged commit 0d1422b into matplotlib:master Mar 7, 2016

2 checks passed

continuous-integration/appveyor/pr AppVeyor build succeeded
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details

mdboom removed the needs_review label Mar 7, 2016

ericdill deleted the ericdill:module-level-backend branch Mar 8, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment