quickie.factories.generic_task_factory

quickie.factories.generic_task_factory(fn: Callable, *, bases: tuple[T, ...], override_method: str) T
quickie.factories.generic_task_factory(fn: Callable, *, bases: tuple[type[T], ...], override_method: str, extra_kwds: dict[str, Any] | None = None, **kwargs: Unpack[_CommonTaskFactoryKwargs]) type[T]
quickie.factories.generic_task_factory(fn: None = None, *, bases: tuple[type[T], ...], override_method: str, extra_kwds: dict[str, Any] | None = None, **kwargs: Unpack[_CommonTaskFactoryKwargs]) PartialReturnType[T]

Create a task class from a function.

You might find this useful when you have a base class for tasks and you want to create your own decorator that creates tasks from functions.

Other decorators like task(), script(), and command() use this function internally.

class MyModuleTask(tasks.Command):
    def get_binary(self):
        return "python"

    def get_extra_args(self):
        raise NotImplementedError

    def get_args(self):
        return ["-m", "my_module", self.get_extra_args()]

def module_task(fn=None, **kwargs):
    return generic_task(
        fn,
        bases=(MyModuleTask,),
        override_method=tasks.Command.get_extra_args.__name__,
        **kwargs,
    )

@module_task(name="hello")
def hello_module_task(task):
    """"Run my_module with 'hello' argument."""
    return ["hello"]
Parameters:
  • fn – The function to create the task from. If None, a partial function will be returned, so you can use this function as a decorator with the arguments.

  • name – The name of the task.

  • extra_args – If the task accepts extra arguments.

  • bind – If true, the first parameter of the function will be the task class instance.

  • condition – The condition to check before running the task.

  • before – The tasks to run before the task.

  • after – The tasks to run after the task.

  • cleanup – The tasks to run after the task, even if it fails.

  • bases – The base classes for the task.

  • override_method – The method to override in the task.

  • extra_kwds – Extra keyword arguments for the task class.

Returns:

The task class, or, if fn is None, a partial function to be used as a decorator for a function.