FunctionBasedStep#

class petpal.pipelines.steps_base.FunctionBasedStep(name: str, function: Callable, *args, **kwargs)#

Bases: StepsAPI

A step in a processing pipeline based on a callable function.

This class allows for the execution of a given function with specified arguments and keyword arguments, validating that all mandatory parameters are provided.

Variables:
  • name (str) – The name of the step.

  • function (Callable) – The function to be executed in this step.

  • args (tuple) – Positional arguments to be passed to the function.

  • kwargs (ArgsDict) – Keyword arguments to be passed to the function.

  • func_sig (inspect.Signature) – The signature of the function for validating arguments.

Initializes a function-based step in the processing pipeline.

Parameters:
  • name (str) – The name of the step.

  • function (Callable) – The function to be executed in this step.

  • *args – Positional arguments to be passed to the function.

  • **kwargs – Keyword arguments to be passed to the function.

get_function_args_not_set_in_kwargs() ArgsDict#

Retrieves arguments of the function that are not set in the keyword arguments.

Returns:

ArgsDict – A dictionary of function arguments that have not been set in the keyword arguments.

get_empty_default_kwargs() list#

Identifies arguments that have not been provided and lack default values.

Returns:

list – A list of argument names that have no default values and are not provided.

validate_kwargs_for_non_default_have_been_set() None#

Validates that all mandatory arguments have been provided.

Raises:

RuntimeError – If any mandatory arguments are missing.

execute()#

Executes the function with the provided arguments and keyword arguments.

Raises:

The function may raise any exceptions that its implementation can throw.

generate_kwargs_from_args() ArgsDict#

Converts positional arguments into keyword arguments.

Returns:

ArgsDict – A dictionary where positional arguments are mapped to their corresponding parameter names.

__str__()#

Returns a detailed string representation of the FunctionBasedStep instance.

Returns:

str – A string describing the step, including its name, function, arguments, and keyword arguments.

__repr__()#

Returns an unambiguous string representation of the FunctionBasedStep instance.

Returns:

str – A string representation showing how the FunctionBasedStep can be recreated.

all_args_non_empty_strings()#

Checks if all positional arguments are non-empty strings.

Returns:

bool – True if all positional arguments are non-empty strings, False otherwise.

all_kwargs_non_empty_strings()#

Checks if all keyword arguments are non-empty strings.

Returns:

bool – True if all keyword arguments are non-empty strings, False otherwise.

can_potentially_run()#

Determines if the step can potentially be executed based on argument validation. Very simply checks if all arguments and keyword arguments are non-empty strings.

Returns:

bool – True if the step can potentially run, False otherwise.

abstractmethod set_input_as_output_from(*sending_steps)#

Sets the input of the current step as the output from a list of steps.

Parameters:

*sending_steps – The previous steps from which the output will be used as input for the current step.

Raises:

NotImplementedError – This method should be implemented by subclasses.

Notes

For a concrete example, take a look at: TACsFromSegmentationStep

Important

If a step takes multiple input steps. the implementation will have a defined order for steps.

abstractmethod infer_outputs_from_inputs(out_dir: str, der_type: str, suffix: str = None, ext: str = None, **extra_desc)#

Infers output files from input data based on the specified output directory, derivative type, optional suffix and extension, plus any extra descriptions.

Parameters:
  • out_dir (str) – The directory where the output files will be saved.

  • der_type (str) – The type of derivative being produced.

  • suffix (str, optional) – An optional suffix for the output files.

  • ext (str, optional) – An optional extension for the output files.

  • **extra_desc – Additional keyword arguments for extra descriptions to be included.

Raises:

NotImplementedError – This method should be implemented by subclasses.

Notes

For a concrete example, take a look at: TACsFromSegmentationStep

__call__(*args, **kwargs)#