-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
MEP27 Decouple pyplot from backends (refactoring Gcf out of backend code) #4143
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
Changes from 1 commit
24caf2b
2b05d38
f4fc354
0b31e3a
6fb452e
0a868a2
61ba2b4
f0eb84c
8fe9cd7
494e5f1
ed16178
21b8f58
cf42e3b
f027b16
24b7b73
bc99129
7f7f05e
713abcb
80adaaf
4e5f69d
160ef57
b6d6acc
ecd5038
f8e83fe
c53b79a
34c6b12
8a4268a
44df199
860a8ed
c44e744
2fe9215
3b434ef
490629f
8eb987b
224a4f3
cdbd51b
50e3719
85be519
7edaf5a
8e6e252
72575cb
4a78246
e300707
ee76451
6f0c7ab
ae9bf5b
fb004e0
1d2095b
24e43b3
208c3be
a44ebd9
f8f9cf2
0e09a54
a38b6d7
64f0c61
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,22 +31,10 @@ def get_backend_name(name=None): | |
return backend_name | ||
|
||
|
||
def get_backends(): | ||
def get_backend(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tacaswell @OceanWolf what about moving this a little bit up and making it a property There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latter on, if we get it right, we can add a setter, and remove the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't fully follow what you mean. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @fariza yes, I put the setter as the basic idea... At the moment we have I have written the code with the possibility to:
Not too convinced about the need to move the module method There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am still confused. Are you suggesting putting a property on the top-level mpl module? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, why not?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For one thing, doing that requires doing some non-standard things to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. OK. That might be a problem.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any objections to just making/marking this module method as private module method and returning to this in a later PR/issue? |
||
backend_name = get_backend_name() | ||
_temp = __import__(backend_name, globals(), locals(), | ||
['Window', 'Toolbar2', 'FigureCanvas', 'MainLoop'], 0) | ||
try: | ||
Window = _temp.Window | ||
Toolbar2 = _temp.Toolbar2 | ||
FigureCanvas = _temp.FigureCanvas | ||
MainLoop = _temp.MainLoop | ||
except AttributeError: | ||
Window = None | ||
Toolbar2 = None | ||
FigureCanvas = None | ||
MainLoop = getattr(_temp, 'show', do_nothing_show) | ||
|
||
return FigureCanvas, Window, Toolbar2, MainLoop | ||
return __import__(backend_name, globals(), locals(), | ||
[backend_name], 0) | ||
|
||
|
||
def pylab_setup(name=None): | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1562,7 +1562,7 @@ def __setstate__(self, state): | |
import matplotlib.backend_managers as managers | ||
allnums = plt.get_fignums() | ||
num = max(allnums) + 1 if allnums else 1 | ||
if managers.Window is not None: # Can we use the new code? | ||
if hasattr(plt._backend_mod, 'Window'): # Can we use MEP 27 code? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. will do, see OceanWolf#4 remember ;). |
||
mgr = managers.FigureManager(self, num) | ||
else: | ||
mgr = plt._backend_mod.new_figure_manager_given_figure(num, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -249,7 +249,7 @@ def show(*args, **kw): | |
described above. | ||
""" | ||
global _show | ||
if backend_managers.Window is not None: # Can we use the new code? | ||
if hasattr(_backend_mod, 'Window'): # Can we use the new code? | ||
return _pylab_helpers.Gcf.show_all(*args, **kw) | ||
else: | ||
_show(*args, **kw) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. missing a |
||
|
@@ -528,7 +528,7 @@ def figure(num=None, # autoincrement if None, else integer from 1-N | |
if get_backend().lower() == 'ps': | ||
dpi = 72 | ||
|
||
if backend_managers.Window is not None: # Can we use the new code? | ||
if hasattr(_backend_mod, 'Window'): # Can we use the MEP 27 code? | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @tacaswell how do you see this way of getting the new figure manager? |
||
fig = FigureClass(figsize=figsize, dpi=dpi, facecolor=facecolor, | ||
edgecolor=edgecolor, frameon=frameon, **kwargs) | ||
figManager = backend_managers.FigureManager(fig, num) | ||
|
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 should use
super
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.
Any reason for using
super()
? Personally I find it more clunky and difficult to read/modify, especially in multiple inheritance, calling it this way we have fine control making it explicitly clear which class you call.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.
because
super
is the right way to deal with MI. If you do it by hand there are ways for it to not call all of the base classes it needs to or call some base classes more than once. Don't re-invent what Guido has already done for us 😉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.
Okay, been a tough battle but now I think I understand super, I saw it as only a top down thing, not a sideways thing... they should really rename
super
as, at least to me, it impliesparent
when it doesn't work like that at all... wow, mind blown! This will take some time for me to get accustomed to... 😄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.
My in to understanding 'super' was to consider the mro of some classes with nasty MI. That is what turns the sidways thing into the parent thing.
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.
How many classes does that touch? One of the issues with super is that like
const
in c++ or the GPL it is viral.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.
They derive just from the MPL base and from the backend GUI component.
Yes, I see
super()
viral nature, one of the reasons which makes we wary of using it, but you implied in theQt
branch that you thought we should use it everywhere... I just want to make sure if we use it, we use it properly, super really works all or nothing (and I do like it because of diamond inheritance). I think I still need to do a few plays with it to fully grasp the paradigm shift in using it with arguments...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.
@tacaswell, regarding your earlier comment about "understanding 'super' was to consider the mro of some classes with nasty MI": to me this doesn't necessarily imply that we should be plastering "super" all over the place; we should be tying hard to avoid "nasty MI". I'm always worried about the code base getting harder and harder to understand. Sometimes I'm close to the point of giving up, and saying that as an amateur, I just can't handle it any more. Many times when I plunge in to try to figure out a problem, it takes too long. Each fancy trick, each complicated inheritance tree, makes it less likely that a given mpl user will be able to submit a PR fixing a bug, instead of merely reporting the bug. OK, enough tirade. I learned to (sort of) like decorators; maybe I will get used to "super" if we end up relying on 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.
I agree we should avoid MI, but in the case of the gui backends we already
have it and using super as it is designed should make that code
simpler/easier to understand (and make the cases where we are using single
inheritance a bit more robust to refactoring and is defensive programming.
I think that the improvements to super in 3 are one of the biggest selling
points).
It is my sense that the hardest to understand code we have comes from when
we try to avoid using language features (or it was written before the
feature was added) and do something in a 'simpler' way which ends up being
many more lines of brittle code.
At it's core all super is doing is saying 'try to find this thing one layer
up in the mro' which, while convenient, does not really matter unless you
have MI with diamonds (other than object).
On Wed, Jun 24, 2015 at 2:15 PM Eric Firing notifications@github.com
wrote:
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 empathise a lot with what you say @efiring. I definitely felt intimidated by the code base when I reported my first bug (#2616), I did a bit of initial digging and decided that that part of the codebase looked way too verbose, "spaghetti code", so yes, I just reported the bug and left. Part of the reason for me wanting to work on these MEPs comes from the desire to make the codebase easier to understand, de-spaghettifi the code.
Decorators appear next on my list of things to learn, I also agree they look complicated. Atm I treat them as voodoo, and as a sort of an embellishment to the code, but that has happened time and again with python (coming from the world of php/java/c) with things list comprehension etcetera, so I see decorators and super in amongst them.
The more I learn about
super
, the more I like it, on the one hand I agree, it has a learning curve to it and that may put people off, on the other hand, if people just see it as voodoo and trust that it works (at least to begin with) and makes the code structure generally clearer then it may actually lower the boundaries to code contribution.I found https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ which helped to convert me, along with experimenting with some of the examples from there (don't worry most of the page gets filled up with comments, so much shorter then it looks).