From a1a64e4134215d32b626a4a59eae8906c8f26cbe Mon Sep 17 00:00:00 2001 From: Timothe Jost <timothe.jost@wanadoo.fr> Date: Tue, 8 Oct 2024 16:23:15 +0200 Subject: [PATCH] adding load_requirement ability to scan through kwargs to output what it needs, if the arg is present, or not --- src/pypelines/__init__.py | 2 +- src/pypelines/pipes.py | 4 ++-- src/pypelines/steps.py | 16 ++++++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/pypelines/__init__.py b/src/pypelines/__init__.py index a1ef774..f3247a5 100644 --- a/src/pypelines/__init__.py +++ b/src/pypelines/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.0.76" +__version__ = "0.0.77" from . import loggs from .pipes import * diff --git a/src/pypelines/pipes.py b/src/pypelines/pipes.py index 1f9391d..6633b0f 100644 --- a/src/pypelines/pipes.py +++ b/src/pypelines/pipes.py @@ -27,7 +27,7 @@ class BasePipeType(Protocol): class BasePipe(BasePipeType, metaclass=ABCMeta): - # this class must implements only the logic to link steps together. + # this class implements only the logic to link steps together. default_extra = None @@ -164,7 +164,7 @@ class BasePipe(BasePipeType, metaclass=ABCMeta): self.pipeline.resolved = False @property - def version(self): + def version(self) -> str: """Return a hash representing the versions of all steps in the object. Returns: diff --git a/src/pypelines/steps.py b/src/pypelines/steps.py index b9ab81b..cb15087 100644 --- a/src/pypelines/steps.py +++ b/src/pypelines/steps.py @@ -1,5 +1,5 @@ -from functools import wraps, partial, update_wrapper -from .loggs import loggedmethod, NAMELENGTH +from functools import wraps, partial, update_wrapper, cache +from .loggs import loggedmethod, NAMELENGTH, getLogger, PypelineLogger from .arguments import autoload_arguments from .utils import to_snake_case @@ -212,7 +212,7 @@ class BaseStep: def __call__(self, *args, **kwargs): """Call the worker method with the given arguments and keyword arguments.""" - return self.worker(*args, **kwargs) + return loggedmethod(self.worker)(*args, **kwargs) def __repr__(self): """Return a string representation of the StepObject in the format: "<pipe_name.step_name StepObject>".""" @@ -720,7 +720,7 @@ class BaseStep: return False return True - def load_requirement(self, pipe_name, session, extra=None): + def load_requirement(self, pipe_name, session, extra=None, **kwargs) -> Any: """Load the specified requirement step for the given pipe name. Args: @@ -734,6 +734,10 @@ class BaseStep: Raises: IndexError: If the required step with the specified pipe name is not found in the requirement stack. """ + + if pipe_name in kwargs.keys(): + return kwargs[pipe_name] + try: req_step = [step for step in self.requirement_stack() if step.pipe_name == pipe_name][-1] except IndexError as e: @@ -767,6 +771,10 @@ class BaseStep: """ raise NotImplementedError + @property + def logger(self) -> PypelineLogger: + return getLogger(self.step_name[:NAMELENGTH]) + @dataclass class StepLevel: -- GitLab