from __future__ import annotations
from typing import Any
from abc import ABC, abstractmethod
from ppc_robot_lib import tasks
[docs]
class AbstractStep(ABC):
"""
Abstract base class for all steps. Each step is required to implement at least the execute method.
Each step should also add its own properties, which represents parameters of the step.
"""
[docs]
@abstractmethod
def execute(self, task_ctx: tasks.TaskContextInterface) -> tasks.StepPerformance | None:
"""
Executes the logic of the step. Must be implemented in subclasses.
:param task_ctx: Task context which contains account credentials.
"""
pass
[docs]
def get_label(self):
"""
:return: Label describing the step. The default implementation returns :py:meth:`step name <get_name>`
together with representation of object from :py:meth:`get_label_args`.
"""
args = self.get_label_args()
if args is not None:
args_str = repr(args)
else:
args_str = ''
return f'{self.get_name()}({args_str})'
[docs]
def get_label_args(self) -> Any | None:
"""
Gets a list of arguments of the current step that is used to represent step arguments in label.
:return: Any object that represents arguments of the current step.
"""
return None
[docs]
@classmethod
def get_name(cls):
"""
:return: Short name of the step, e.g. ``FilterStep``.
"""
return cls.__name__