Skip to content

Traitlets #4762

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

Closed
wants to merge 73 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
73 commits
Select commit Hold shift + click to select a range
c202812
supress ipynb files
rmorshea Aug 6, 2015
9d4092e
todo list
rmorshea Jul 20, 2015
0edf017
refactoring with new workflow
rmorshea Jul 21, 2015
f73f7b6
transform refactoring : see TODO
rmorshea Jul 23, 2015
8b91ade
transform refactoring : see TODO
rmorshea Jul 23, 2015
ff69573
revert .gitignore
rmorshea Jul 23, 2015
602ce41
remove ipynb_checkpoints
rmorshea Jul 23, 2015
97167ac
see TODO
rmorshea Jul 23, 2015
52fdc79
see TODO
rmorshea Jul 23, 2015
de152bc
see TODO
rmorshea Jul 23, 2015
ae5b5ba
transform implamented
rmorshea Jul 30, 2015
5f58d90
progress update
rmorshea Jul 30, 2015
a8a1f18
see TODO
rmorshea Aug 1, 2015
664c02a
last update of refactor
rmorshea Aug 1, 2015
0275157
ignore refactor
rmorshea Aug 1, 2015
e258cd2
last update to refactor
rmorshea Aug 1, 2015
a14f83b
comment change
rmorshea Aug 2, 2015
e238441
rebase with origin/master (up to date with upstream/master)
rmorshea Aug 2, 2015
97f0532
add figure traitlet
rmorshea Aug 5, 2015
e1d976d
shrink file
rmorshea Aug 5, 2015
d85e2c1
progress towards full test suite pass
rmorshea Aug 14, 2015
b6d3e45
errors reduced to pickling and ref counts
rmorshea Aug 14, 2015
be7f591
update rebase
rmorshea Aug 14, 2015
5609b44
fix memory leak in Artist
rmorshea Aug 14, 2015
871388d
fix memory leaks in test_quiver.py
rmorshea Aug 14, 2015
4030397
fix exdict inheritance
rmorshea Aug 15, 2015
5a2160f
fix pickling
rmorshea Aug 15, 2015
b436bee
update traitlets
rmorshea Aug 15, 2015
593e34c
remove print statement
rmorshea Aug 15, 2015
4b6195c
resolve pickling
rmorshea Aug 16, 2015
d11236c
update exdict
rmorshea Aug 16, 2015
1debbd0
simple performance test
rmorshea Aug 16, 2015
bbf1c89
update TODO progress report
rmorshea Aug 16, 2015
709bdac
refactor visible and animated
rmorshea Aug 17, 2015
867899c
shrink file
rmorshea Aug 17, 2015
cfb0713
refactor alpha, but failed alpha blending in agg
rmorshea Aug 17, 2015
e9c8489
refactor rasterize, pickable, evenston
rmorshea Aug 18, 2015
a2e6676
update rebase
rmorshea Aug 18, 2015
299ceb2
FIX: revert changes to gc calls
tacaswell Aug 18, 2015
93945ab
fix memory leak
rmorshea Aug 18, 2015
9934482
see TODO
rmorshea Aug 21, 2015
22e4b0c
change property updates via name
rmorshea Aug 23, 2015
9b65ee0
see TODO
rmorshea Aug 25, 2015
9528a83
base artist refactor complete: see TODO
rmorshea Aug 25, 2015
f69490b
fix sketch_params/path_effects default
rmorshea Aug 25, 2015
afddefe
fix setp/getp, change forced callbacks
rmorshea Aug 25, 2015
cd1d60a
reintroduce traitlets test
rmorshea Aug 26, 2015
89caa0f
fix typo
rmorshea Sep 8, 2015
7717e07
update rebased commits
rmorshea Sep 8, 2015
57131b2
add traitlets as test dep
rmorshea Sep 8, 2015
6aacb91
simplify old value store for forced callbacks
rmorshea Sep 9, 2015
4cf88ff
use new traitlets api (has quiver memory leaks)
rmorshea Sep 16, 2015
bb02b38
add @retrieve decorator
rmorshea Sep 18, 2015
a43cdf9
correct private get
rmorshea Oct 2, 2015
be3de2f
now requires most revent version of traitlets
rmorshea Oct 5, 2015
340df20
reintroduce mute context manager, and begin uncommenting legacy sette…
rmorshea Oct 6, 2015
84ac0ff
edit traitlets as test dep
rmorshea Oct 6, 2015
7dc256a
finish uncommenting setters/getters
rmorshea Oct 8, 2015
d895089
MNT: minor fixes
tacaswell Oct 8, 2015
6ba2c89
TST: use bleeding edge branch for traitlets
tacaswell Oct 8, 2015
0064153
pep8 fixes
rmorshea Oct 9, 2015
ffe9d09
final pep8 fixes
rmorshea Oct 9, 2015
bdf6622
traitlet warning supression
rmorshea Oct 9, 2015
08a6db7
fix pylab example
rmorshea Oct 12, 2015
0d936ed
supress more warnings
rmorshea Oct 14, 2015
9d76e5a
supress more warnings
rmorshea Oct 14, 2015
3826b49
correct impropper validate usage
rmorshea Nov 2, 2015
abba50b
correct after rebase
rmorshea Nov 20, 2015
d8f65db
setattr in SimpleChainedObjects
rmorshea Nov 22, 2015
1917a2d
fix travis.yml after rebase
rmorshea Nov 22, 2015
86a9b69
misc edits, mark as changed only if setter is used
rmorshea Nov 23, 2015
40d5b49
change traitlets warn message
rmorshea Dec 2, 2015
0d1eb25
COMPRESS
rmorshea Mar 9, 2016
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add @retrieve decorator
  • Loading branch information
rmorshea committed Nov 27, 2015
commit bb02b3847ae58ef6f287ac797e3cd02ac44e738e
10 changes: 7 additions & 3 deletions lib/matplotlib/artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,10 @@
TransformedPatchPath, TransformedPath, Transform)
from .path import Path

from .traitlets import (Instance, Configurable, gTransformInstance, Bool, Undefined, Union,
from .traitlets import (Instance, Configurable, TransformInstance, Bool, Undefined, Union,
BaseDescriptor, getargspec, PrivateMethodMixin, Float, TraitError,
Unicode, Stringlike, Callable, Tuple, List, observe, validate, default)
Unicode, Stringlike, Callable, Tuple, List, observe, validate, default,
retrieve)

from urlparse import urlparse

Expand Down Expand Up @@ -88,7 +89,7 @@ class Artist(PrivateMethodMixin, Configurable):
aname = 'Artist'
zorder = 0

transform = gTransformInstance(IdentityTransform())
transform = TransformInstance(None)

@observe('transform')
def _transform_changed(self, change):
Expand All @@ -100,6 +101,7 @@ def _transform_validate(self, commit):
self.transform_set = True
return commit['value']

@retrieve('transform')
def _transform_getter(self, pull):
if pull['trait']._conversion_method:
return pull['value'](self.axes)
Expand Down Expand Up @@ -192,6 +194,7 @@ def _pickabe_validate(self, commit):
repl = (commit['trait'].name, self.__class__.__name__)
raise TraitError(msg % repl)

@retrieve('pickable')
def _pickable_getter(self, pull):
return (self.figure is not None and
self.figure.canvas is not None and
Expand Down Expand Up @@ -265,6 +268,7 @@ def _agg_filter_changed(self, change):

snap = Bool(None, allow_none=True)

@retrieve('snap')
def _snap_getter(self, pull):
if rcParams['path.snap']:
return pull['value']
Expand Down
2 changes: 0 additions & 2 deletions lib/matplotlib/axes/_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,6 @@
is_sequence_of_strings = cbook.is_sequence_of_strings




def _process_plot_format(fmt):
"""
Process a MATLAB style color/line style format string. Return a
Expand Down
5 changes: 2 additions & 3 deletions lib/matplotlib/axis.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import numpy as np
import warnings

from .traitlets import gTransformInstance, Instance
from .traitlets import Instance, retrieve

GRIDLINE_INTERPOLATION_STEPS = 180

Expand Down Expand Up @@ -619,8 +619,6 @@ class Axis(artist.Artist):
"""
OFFSETTEXTPAD = 3

transform = gTransformInstance(None)

label = Instance(mtext.Text, allow_none=True)

def __str__(self):
Expand Down Expand Up @@ -688,6 +686,7 @@ def set_label_coords(self, x, y, transform=None):
self.label.set_position((x, y))
self.stale = True

@retrieve('transform')
def _transform_getter(self, pull):
return self._scale.get_transform()

Expand Down
8 changes: 3 additions & 5 deletions lib/matplotlib/offsetbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
from matplotlib.patches import bbox_artist as mbbox_artist
from matplotlib.text import _AnnotationBase

from .traitlets import gTransformInstance, observe
from .traitlets import observe, retrieve

DEBUG = False

Expand Down Expand Up @@ -595,8 +595,6 @@ class DrawingArea(OffsetBox):
boundaries of the parent.
"""

transform = gTransformInstance(None, allow_none=True)

def __init__(self, width, height, xdescent=0.,
ydescent=0., clip=False):
"""
Expand Down Expand Up @@ -632,6 +630,7 @@ def clip_children(self, val):
self._clip_children = bool(val)
self.stale = True

@retrieve('transform')
def _transform_getter(self, pull):
"""
Return the :class:`~matplotlib.transforms.Transform` applied
Expand Down Expand Up @@ -915,8 +914,6 @@ class AuxTransformBox(OffsetBox):
calculated in the transformed coordinate.
"""

transform = gTransformInstance(None, allow_none=True)

def __init__(self, aux_transform):
self.aux_transform = aux_transform
OffsetBox.__init__(self)
Expand All @@ -937,6 +934,7 @@ def add_artist(self, a):
a.transform = self.transform
self.stale = True

@retrieve('transform')
def _transform_getter(self, pull):
return self.aux_transform + \
self.ref_offset_transform + \
Expand Down
6 changes: 2 additions & 4 deletions lib/matplotlib/patches.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@
from matplotlib.bezier import split_path_inout, get_cos_sin
from matplotlib.bezier import make_path_regular, concatenate_paths

from .transforms import IdentityTransform
from .traitlets import gTransformInstance, validate
from .traitlets import validate, retrieve


# these are not available for the object inspector until after the
Expand Down Expand Up @@ -70,8 +69,6 @@ class Patch(artist.Artist):
validCap = ('butt', 'round', 'projecting')
validJoin = ('miter', 'round', 'bevel')

transform = gTransformInstance(IdentityTransform())

def __str__(self):
return str(self.__class__).split('.')[-1]

Expand Down Expand Up @@ -196,6 +193,7 @@ def get_extents(self):
"""
return self.get_path().get_extents(self.transform)

@retrieve('transform')
def _transform_getter(self, pull):
return self.get_patch_transform() + pull['value']

Expand Down
2 changes: 2 additions & 0 deletions lib/matplotlib/tests/test_collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import matplotlib.transforms as mtransforms
from matplotlib.collections import EventCollection
from matplotlib.testing.decorators import cleanup, image_comparison
from matplotlib.traitlets import retrieve


def generate_EventCollection_plot():
Expand Down Expand Up @@ -552,6 +553,7 @@ def __init__(self, **kwargs):
super(SquareCollection, self).__init__(
4, rotation=np.pi/4., **kwargs)

@retrieve('transform')
def _transform_getter(self, pull):
"""Return transform scaling circle areas to data space."""
ax = self.axes
Expand Down
4 changes: 3 additions & 1 deletion lib/matplotlib/tests/test_traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
from IPython.utils.traitlets import TraitError, HasTraits

from matplotlib.traitlets import (Color, exdict, OnGetMixin, PrivateMethodMixin,
Int, Configurable, observe, validate)
Int, Configurable, observe, validate, retrieve)

def test_exdict():
e = exdict()
Expand All @@ -25,6 +25,7 @@ class gInt(OnGetMixin, Int): pass
class A(PrivateMethodMixin, Configurable):

attr = gInt(0)
@retrieve('attr')
def _attr_getter(self, value, trait):
return value + 1

Expand Down Expand Up @@ -59,6 +60,7 @@ class gInt(OnGetMixin, Int): pass
class A(PrivateMethodMixin, Configurable):

attr = gInt(0)
@retrieve('attr')
def _attr_getter(self, value, trait):
return value + 1

Expand Down
46 changes: 31 additions & 15 deletions lib/matplotlib/traitlets.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
Dict, List, Instance, Union,
Unicode, Tuple, TraitError,
Undefined, BaseDescriptor,
getargspec, observe, default, validate)
getargspec, observe, default,
validate, EventHandler)
except ImportError:
# IPython3 imports
from IPython.utils.traitlets.config import Configurable, Config
from IPython.utils.traitlets import (TraitType, Int, Float, Bool,
Dict, List, Instance, Union, Unicode,
Tuple, TraitError, Undefined, BaseDescriptor,
getargspec, observe, default, validate)
getargspec, observe, default, validate,
EventHandler)

import re
import types
Expand Down Expand Up @@ -81,24 +83,40 @@ def _retrieve_trait(self, name):
raise TraitError(msg % (name, self.__class__.__name__))
return trait

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm having trouble with loading things after pickling. Right now, the _default_generator method in the "exdict" class I have to force callbacks, is no longer there (as is expected since I removed it in __getstate__). I would expect the following bit of code in "PrivateMethodMixin" to fix this, however it instead raises an error claiming that _rasterized is no longer an attribute of a Rectangle instance. I suspect that this is because I'm overriding a __setstate__ method somewhere else, but I'm not sure:

    def __setstate__(self, state):
        meth = lambda klass, key: getattr(klass, key).default_value
        state['_trait_values']._default_generator = MethodType(meth, self.__class__)
        return state.update(self.__dict__)

I'm running this to test: $ python lib/matplotlib/tests/test_pickle.py

class OnGetMixin(object):
def retrieve(name):
return RetrieveHandler(name)

def __init__(self, *args, **kwargs):
super_obj = super(OnGetMixin,self)
self.__base_get__ = super_obj.__get__
self.__base_set__ = super_obj.__set__
super_obj.__init__(*args, **kwargs)
class RetrieveHandler(EventHandler):

def __init__(self, name):
self._name = name

def instance_init(self, inst):
if not hasattr(inst, '_retrieve_handlers'):
inst._retrieve_handlers = {}
if self._name in inst._retrieve_handlers:
raise TraitError("A retriever for the trait '%s' has "
"already been registered" % self._name)
method = types.MethodType(self.func, inst)
inst._retrieve_handlers[self._name] = method

class OnGetMixin(object):

def __get__(self, obj, cls=None):
value = super(OnGetMixin,self).__get__(obj,cls)
method = getattr(obj, '_'+self.name+'_getter', None)
if value is not self and method is not None:
method = getattr(obj, '_'+self.name+'_getter')
if obj is None:
return self
value = super(OnGetMixin,self).get(obj, cls)
if self.name in obj._retrieve_handlers:
method = obj._retrieve_handlers[self.name]
value = method({'value': value, 'owner':obj, 'trait':self})
return value

def instance_init(self, inst):
if not hasattr(inst, '_retrieve_handlers'):
inst._retrieve_handlers = {}
super(OnGetMixin, self).instance_init(inst)

class TransformInstance(TraitType):
class TransformInstance(OnGetMixin, TraitType):

info_text = ('a Transform instance or have an'
' `_as_mpl_transform` method')
Expand All @@ -125,8 +143,6 @@ def validate(self, obj, value):
return value._as_mpl_transform
trait.error(obj, value)

class gTransformInstance(OnGetMixin,TransformInstance): pass

#!Note : this is what the transform instance would
# look like if getters were to be avoided entirely.
# `_name_validate` would handle "on set" events
Expand Down