quickie.factories.task_factory_helper
- quickie.factories.task_factory_helper(obj: Callable | type[T], *, base: type[T], override_method: str) T
- quickie.factories.task_factory_helper(obj: Callable | type[T], *, name: str | None, aliases: Sequence[str] | None = None, private: bool = False, args: Sequence[Arg | str | Sequence[str]] | None = None, extra_args: bool | None, bind: bool, condition: BaseCondition | None, before: Sequence[Callable] | None, after: Sequence[Callable] | None, cleanup: Sequence[Callable] | None, base: type[T], override_method: str, attrs: dict[str, Any] | None = None, kwargs: dict[str, Any] | None = None) T
- quickie.factories.task_factory_helper(obj: None = None, *, private: bool = False, base: type[T], override_method: str, attrs: dict[str, Any] | None = None, kwargs: dict[str, Any] | None = None, args: Sequence[Arg | str | Sequence[str]] | None = None, extra_args: bool | None, bind: bool, condition: BaseCondition | None, before: Sequence[Callable] | None, after: Sequence[Callable] | None, cleanup: Sequence[Callable] | None) PartialReturnType[T]
- quickie.factories.task_factory_helper(obj: Callable | type[T] | None = None, *, name: str | None = None, aliases: Sequence[str] | None = None, private: bool = False, args: Sequence[Arg | str | Sequence[str]] | None = None, extra_args: bool | None = None, bind: bool = False, condition: BaseCondition | None = None, before: Sequence[Callable] | None = None, after: Sequence[Callable] | None = None, cleanup: Sequence[Callable] | None = None, base: type[T], override_method: str, attrs: dict[str, Any] | None = None, kwargs: dict[str, Any] | None = None) DecoratorReturnType[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
quickie.task(),quickie.script(), andquickie.command()use this function internally.class MyModuleTask(tasks.Command): def get_binary(self): return "python" def get_extra_cmd_args(self): raise NotImplementedError def get_cmd_args(self): return ["-m", "my_module", self.get_extra_cmd_args()] def module_task(obj=None, **kwargs): return generic_task( obj, base=MyModuleTask, override_method=tasks.Command.get_extra_cmd_args.__name__, **kwargs, ) @module_task(name="hello") def hello_module_task(task): """"Run my_module with 'hello' argument.""" return ["hello"]
- Parameters:
obj – 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.
aliases – The aliases of the task.
private – If true, the task is private and will not be shown in the
args – The arguments for the task. Can pass Arg objects, but also strings or tuples of strings that will be used as a shortcut for the Arg object. For example, args=[”–arg1”, (”–name”, “-n”)] is equivalent to args=[Arg(”–arg1”), Arg(”–name”, “-n”)].
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.
base – The base class for the task.
override_method – The method to override in the task.
attrs – Extra attributes for the task class. Ignored if obj is a class.
kwargs – Extra keyword arguments to initialize the task.
- Returns:
The task class, or, if obj is None, a partial function to be used as a decorator for a function.