##// END OF EJS Templates
use canning hook in dependent...
MinRK -
Show More
@@ -59,10 +59,12 b' class dependent(object):'
59 self.df = df
59 self.df = df
60 self.dargs = dargs
60 self.dargs = dargs
61 self.dkwargs = dkwargs
61 self.dkwargs = dkwargs
62
62
63 def __call__(self, *args, **kwargs):
63 def check_dependency(self):
64 if self.df(*self.dargs, **self.dkwargs) is False:
64 if self.df(*self.dargs, **self.dkwargs) is False:
65 raise UnmetDependency()
65 raise UnmetDependency()
66
67 def __call__(self, *args, **kwargs):
66 return self.f(*args, **kwargs)
68 return self.f(*args, **kwargs)
67
69
68 if not py3compat.PY3:
70 if not py3compat.PY3:
@@ -64,7 +64,7 b' class CannedObject(object):'
64 obj = self.obj
64 obj = self.obj
65 for key in self.keys:
65 for key in self.keys:
66 setattr(obj, key, uncan(getattr(obj, key), g))
66 setattr(obj, key, uncan(getattr(obj, key), g))
67
67
68 if self.hook:
68 if self.hook:
69 self.hook = uncan(self.hook, g)
69 self.hook = uncan(self.hook, g)
70 self.hook(obj, g)
70 self.hook(obj, g)
@@ -308,6 +308,11 b' def uncan_sequence(obj, g=None):'
308 else:
308 else:
309 return obj
309 return obj
310
310
311 def _uncan_dependent_hook(dep, g=None):
312 dep.check_dependency()
313
314 def can_dependent(obj):
315 return CannedObject(obj, keys=('f', 'df'), hook=_uncan_dependent_hook)
311
316
312 #-------------------------------------------------------------------------------
317 #-------------------------------------------------------------------------------
313 # API dictionaries
318 # API dictionaries
@@ -316,7 +321,7 b' def uncan_sequence(obj, g=None):'
316 # These dicts can be extended for custom serialization of new objects
321 # These dicts can be extended for custom serialization of new objects
317
322
318 can_map = {
323 can_map = {
319 'IPython.parallel.dependent' : lambda obj: CannedObject(obj, keys=('f','df')),
324 'IPython.parallel.dependent' : can_dependent,
320 'numpy.ndarray' : CannedArray,
325 'numpy.ndarray' : CannedArray,
321 FunctionType : CannedFunction,
326 FunctionType : CannedFunction,
322 bytes : CannedBytes,
327 bytes : CannedBytes,
General Comments 0
You need to be logged in to leave comments. Login now