ObjectBasedStep#

class petpal.pipelines.steps_base.ObjectBasedStep(name: str, class_type: type, init_kwargs: dict, call_kwargs: dict)#

Bases: StepsAPI

A step in a processing pipeline that is based on instantiating and invoking methods on an object.

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

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

  • class_type (type) – The class type to be instantiated in this step.

  • init_kwargs (ArgsDict) – Keyword arguments for initializing the class.

  • call_kwargs (ArgsDict) – Keyword arguments for invoking the class.

  • init_sig (inspect.Signature) – The initialization signature of the class for validating arguments.

  • call_sig (inspect.Signature) – The call signature of the class for validating arguments.

Initializes an object-based step in the processing pipeline.

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

  • class_type (type) – The class type to be instantiated in this step.

  • init_kwargs (dict) – Keyword arguments for initializing the class.

  • call_kwargs (dict) – Keyword arguments for invoking the class.

validate_kwargs()#

Validates that all mandatory initialization and call arguments have been provided.

Raises:

RuntimeError – If any mandatory arguments are missing.

static get_args_not_set_in_kwargs(sig: inspect.Signature, kwargs: dict) dict#

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

Parameters:
  • sig (inspect.Signature) – The signature of the function or method.

  • kwargs (dict) – The keyword arguments provided.

Returns:

dict – A dictionary of arguments that are not set in the keyword arguments.

get_empty_default_kwargs(sig: inspect.Signature, set_kwargs: dict) list#

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

Parameters:
  • sig (inspect.Signature) – The signature of the function or method.

  • set_kwargs (dict) – The keyword arguments provided.

Returns:

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

execute() None#

Instantiates the class and invokes it with the provided arguments.

Raises:

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

__str__()#

Returns a detailed string representation of the ObjectBasedStep instance.

Returns:

str – A string describing the step, including its name, class, initialization, and call arguments.

__repr__()#

Returns an unambiguous string representation of the ObjectBasedStep instance.

Returns:

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

all_init_kwargs_non_empty_strings()#

Checks if all initialization keyword arguments are non-empty strings.

Returns:

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

all_call_kwargs_non_empty_strings()#

Checks if all call keyword arguments are non-empty strings.

Returns:

bool – True if all call 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 __init__ and __call__ keyword arguments for the object 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)#