diff options
author | Théo de la Hogue | 2024-03-27 17:09:13 +0100 |
---|---|---|
committer | Théo de la Hogue | 2024-03-27 17:09:13 +0100 |
commit | 8e5dba2318e86f6dbd787ad2c59ab86686e19215 (patch) | |
tree | 7d9e6771415922aaa87bc2663b2d716aa6dbcaea /src/argaze/DataFeatures.py | |
parent | f66b584c38b5ec9b9e1515ee6fb4b0826cd7ca2a (diff) | |
download | argaze-8e5dba2318e86f6dbd787ad2c59ab86686e19215.zip argaze-8e5dba2318e86f6dbd787ad2c59ab86686e19215.tar.gz argaze-8e5dba2318e86f6dbd787ad2c59ab86686e19215.tar.bz2 argaze-8e5dba2318e86f6dbd787ad2c59ab86686e19215.tar.xz |
Propagating context entrance.
Diffstat (limited to 'src/argaze/DataFeatures.py')
-rw-r--r-- | src/argaze/DataFeatures.py | 87 |
1 files changed, 57 insertions, 30 deletions
diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py index a8ede6f..674a8d9 100644 --- a/src/argaze/DataFeatures.py +++ b/src/argaze/DataFeatures.py @@ -619,23 +619,68 @@ class TimestampedImages(TimestampedObjectsList): TimestampedObjectsList.__init__(self, TimestampedImage, images) def PipelineStepInit(method): - """Define a decorator use into PipelineStepObject class to declare pipeline step init method.""" + """Define a decorator use into PipelineStepObject class to wrap pipeline step __init__ method.""" def wrapper(self, **kwargs): - """Wrap pipeline step init method to update PipelineStepObject attributes with arguments after init call. + """Wrap pipeline __init__ init method to update PipelineStepObject attributes with arguments after init call. Parameters: kwargs: any arguments defined by PipelineStepMethodInit. """ - method(self, **kwargs) PipelineStepObject.update_attributes(self, kwargs) return wrapper +def PipelineStepEnter(method): + """Define a decorator use into PipelineStepObject class to wrap pipeline step __enter__ method.""" + + def wrapper(self): + """Wrap pipeline step __enter__ method to call super, observers and children __enter__ method.""" + + PipelineStepObject.__enter__(self) + + method(self) + + # Start children pipeline step objects + for child in self.children: + + child.__enter__() + + # Start observers + for observer in self.observers: + + observer.__enter__() + + return self + + return wrapper + +def PipelineStepExit(method): + """Define a decorator use into PipelineStepObject class to wrap pipeline step __exit__ method.""" + + def wrapper(self, exception_type, exception_value, exception_traceback): + """Wrap pipeline step __exit__ method to call super, observers and children __exit__ method.""" + + PipelineStepObject.__exit__(self, exception_type, exception_value, exception_traceback) + + # Stop observers + for observer in self.observers: + + observer.__exit__(exception_type, exception_value, exception_traceback) + + # Stop children pipeline step objects + for child in self.children: + + child.__exit__(exception_type, exception_value, exception_traceback) + + method(self, exception_type, exception_value, exception_traceback) + + return wrapper + def PipelineStepAttributeSetter(method): - """Define a decorator use into PipelineStepObject class to declare pipeline step attribute setter.""" + """Define a decorator use into PipelineStepObject class to wrap pipeline step attribute setter.""" def wrapper(self, new_value, unwrap: bool = False): """Wrap pipeline step attribute setter to load attribute from file. @@ -719,13 +764,12 @@ class PipelineStepObject(): Define class to assess pipeline step methods execution time and observe them. """ - @PipelineStepInit def __init__(self, **kwargs): """Initialize PipelineStepObject.""" logging.debug('%s.__init__', type(self).__name__) - # Init private attribute + # Init private attributes self.__name = None self.__observers = [] self.__execution_times = {} @@ -733,37 +777,20 @@ class PipelineStepObject(): # Parent attribute will be setup later by parent it self self.__parent = None + # Update attributes + self.update_attributes(kwargs) + def __enter__(self): - """At with statement start.""" + """Define default method to enter into pipeline step object context.""" logging.debug('%s.__enter__', type(self).__name__) - # Start children pipeline step objects - for child in self.children: - - child.__enter__() - - # Start observers - for observer in self.__observers: - - observer.__enter__() - return self - def __exit__(self, exception_type, exception_value, exception_traceback): - """At with statement end.""" - - logging.debug('%s.__exit__', type(self).__name__) - - # End observers - for observer in self.__observers: - - observer.__exit__(exception_type, exception_value, exception_traceback) - - # End children pipeline step objects - for child in self.children: + def __exit__(self, type, value, traceback): + """Define default method to exit from pipeline step object context.""" - child.__exit__(exception_type, exception_value, exception_traceback) + logging.debug('PipelineStepObject.__exit__') def update_attributes(self, object_data: dict): """Update pipeline step object attributes with dictionary.""" |