From 81c0455a01f8464d5611c0cec9499010f0a5b450 Mon Sep 17 00:00:00 2001 From: Théo de la Hogue Date: Mon, 19 Feb 2024 14:43:12 +0100 Subject: Adding children property to PipelineStepObject to iterate over all sub PipeLineStepObjects. Appending working directory to Python path. --- src/argaze/DataFeatures.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/argaze/DataFeatures.py b/src/argaze/DataFeatures.py index 62f81a6..edbf8e9 100644 --- a/src/argaze/DataFeatures.py +++ b/src/argaze/DataFeatures.py @@ -418,6 +418,11 @@ class PipelineStepObject(): def __enter__(self): """At with statement start.""" + # Start children pipeline step objects + for child in self.children: + + child.__enter__() + # Start observers for observer_name, observer in self.__observers.items(): @@ -425,13 +430,18 @@ class PipelineStepObject(): return self - def __exit__(self, type, value, traceback): + def __exit__(self, exception_type, exception_value, exception_traceback): """At with statement end.""" # End observers for observer_name, observer in self.__observers.items(): - observer.__exit__(type, value, traceback) + observer.__exit__(exception_type, exception_value, exception_traceback) + + # End children pipeline step objects + for child in self.children: + + child.__exit__(exception_type, exception_value, exception_traceback) @property def name(self) -> str: @@ -483,6 +493,11 @@ class PipelineStepObject(): working_directory: folder path where to load files when a dictionary value is a relative filepath. """ + # Append working directory to the Python path + if working_directory is not None: + + sys.path.append(working_directory) + # Load name try: @@ -660,7 +675,7 @@ class PipelineStepObject(): return tabs @property - def properties(self) -> list: + def properties(self) -> Tuple[name, any]: """Iterate over pipeline step properties values.""" for name, item in self.__class__.__dict__.items(): @@ -679,6 +694,20 @@ class PipelineStepObject(): yield name, getattr(self, name) + @property + def children(self) -> object: + """Iterate over children pipeline step objects.""" + + for name, item in self.__class__.__dict__.items(): + + if isinstance(item, property): + + attr = getattr(self, name) + + if PipelineStepObject in attr.__class__.__bases__: + + yield attr + def PipelineStepMethod(method): """Define a decorator use into PipelineStepObject class to declare pipeline method. @@ -694,7 +723,6 @@ def PipelineStepMethod(method): args: Any arguments defined by PipelineStepMethod. unwrap: Extra arguments used in wrapper function to call wrapped method directly. """ - if unwrap: return method(self, timestamp, *args) -- cgit v1.1