Checklet mixins

Many checklets share common functionality. This functionality can be provided using mixins. Mixins can provide their own metadata including options, all checklets incorporating a mixin will inherit the mixin’s options.

To define a mixin, create a class that subclasses from CheckletBase:

class MyCheckletMixin(CheckletBase):
    class Meta:
        options = ...

    def do_some_mixthing(self):
        ...

To use a mixin add it to the list of base classes of the checklet, after the Checklet class:

class MyChecklet(Checklet, MyCheckletMixin):
    class Meta:
        options = ...

    def run(self):
        ...
        do_some_mixthing()
        ...

A very common pattern is a mixin that adds a decorator that wraps the run() method of the checklet to modify the result.

class MyDecoratorCheckletMixin(CheckletBase):
    class Meta:
        options = ...

    @classmethod
    def decorator(cls, runner: typing.Callable[..., CheckletResult]):
        @wraps(runner)
        def wrapper(step, *args, **kwargs) -> CheckletResult:
            return step._modify_result(
                runner(step, *args, **kwargs)
            )

       return wrapper

    def _modify_result(self, result: CheckletResult) -> CheckletResult:
        ...

class MyChecklet(Checklet, MyDecoratorCheckletMixin):
    class Meta:
        options = ...

    @MyDecoratorCheckletMixin.decorator
    def run(self) -> CheckletResult:
        ...

Note

Checklet.run() can return either a ResultsBundle or a CheckletResult. However, the mixin defined above expects run() to return a CheckletResult.

It would be possible to make the mixin more flexible by checking the return type of the run() method, but this adds unnecessary complexity. The CheckletResult class was introduced to make decorating the run() method easier, and allowing returning a ResultsBundle from run() is retained for backwards compatibility.

Mixins can also subclass other mixins. In that case, the CheckletBase must be included last:

class MySubclassedCheckletMixin(MyCheckletMixin, CheckletBase):
    ...

Mixins provided by mtrchk.org.momotor.base

checklet mixin class mtrchk.org.momotor.base.checklet.tasks.StepTasksCheckletMixin

Checklet mixin to support multiple tasks for a step

tasks@scheduler option

Enable multiple tasks for this step. If not provided, a single task is generated for this step.

See Scheduler tasks option for the documentation of this option.

Type:

string

Required:

False

Multiple:

False

Location:

config, recipe, step

Default:

No default