FunctionBasedStep ============================================= .. py:class:: petpal.pipelines.steps_base.FunctionBasedStep(name: str, function: Callable, *args, **kwargs) Bases: :py:obj:`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. :ivar name: The name of the step. :vartype name: str :ivar function: The function to be executed in this step. :vartype function: Callable :ivar args: Positional arguments to be passed to the function. :vartype args: tuple :ivar kwargs: Keyword arguments to be passed to the function. :vartype kwargs: ArgsDict :ivar func_sig: The signature of the function for validating arguments. :vartype func_sig: inspect.Signature Initializes a function-based step in the processing pipeline. :param name: The name of the step. :type name: str :param function: The function to be executed in this step. :type function: Callable :param \*args: Positional arguments to be passed to the function. :param \*\*kwargs: Keyword arguments to be passed to the function. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: execute() Executes the function with the provided arguments and keyword arguments. :raises The function may raise any exceptions that its implementation can throw.: .. py:method:: 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. .. py:method:: __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. .. py:method:: __repr__() Returns an unambiguous string representation of the FunctionBasedStep instance. :returns: *str* -- A string representation showing how the FunctionBasedStep can be recreated. .. py:method:: 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. .. py:method:: 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. .. py:method:: 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. .. py:method:: set_input_as_output_from(*sending_steps) :abstractmethod: Sets the input of the current step as the output from a list of steps. :param \*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. .. rubric:: Notes For a concrete example, take a look at: :meth:`TACsFromSegmentationStep` .. important:: If a step takes multiple input steps. the implementation will have a defined order for steps. .. py:method:: infer_outputs_from_inputs(out_dir: str, der_type: str, suffix: str = None, ext: str = None, **extra_desc) :abstractmethod: Infers output files from input data based on the specified output directory, derivative type, optional suffix and extension, plus any extra descriptions. :param out_dir: The directory where the output files will be saved. :type out_dir: str :param der_type: The type of derivative being produced. :type der_type: str :param suffix: An optional suffix for the output files. :type suffix: str, optional :param ext: An optional extension for the output files. :type ext: str, optional :param \*\*extra_desc: Additional keyword arguments for extra descriptions to be included. :raises NotImplementedError: This method should be implemented by subclasses. .. rubric:: Notes For a concrete example, take a look at: :meth:`TACsFromSegmentationStep` .. py:method:: __call__(*args, **kwargs)