qkrun.tasks.Task

class qkrun.tasks.Task(name: str | None = None, *, aliases: Sequence[str] | None = None, private: bool = False, wraps: type | Callable | None = None, args: Sequence[Arg | str | Sequence[str]] | None = None, extra_args: bool | None = None, condition: BaseCondition | None = None, before: Sequence[Callable] | None = None, after: Sequence[Callable] | None = None, cleanup: Sequence[Callable] | None = None, watch_paths: Sequence[str] | None = None, watch_ignore_paths: Sequence[str] | None = None, watch_patterns: Sequence[str] | None = None, watch_ignore_patterns: Sequence[str] | None = None, watch_debounce: float | None = None, watch_recursive: bool | None = None)

Base class for all tasks.

__init__(name: str | None = None, *, aliases: Sequence[str] | None = None, private: bool = False, wraps: type | Callable | None = None, args: Sequence[Arg | str | Sequence[str]] | None = None, extra_args: bool | None = None, condition: BaseCondition | None = None, before: Sequence[Callable] | None = None, after: Sequence[Callable] | None = None, cleanup: Sequence[Callable] | None = None, watch_paths: Sequence[str] | None = None, watch_ignore_paths: Sequence[str] | None = None, watch_patterns: Sequence[str] | None = None, watch_ignore_patterns: Sequence[str] | None = None, watch_debounce: float | None = None, watch_recursive: bool | None = None)

Initialize the task.

Parameters:
  • name – The name it can be invoked with. If not provided, it defaults to the class name.

  • aliases – Alternative names it can be invoked with..

  • wraps – The obj (class or function) where the task was defined. If not provided, and the task is not private, it defaults to the class itself.

  • private – Whether the task is private. If not provided, it is private if the class name starts with an underscore.

  • args – The arguments for the task. If not provided, it defaults to the class attribute args.

  • extra_args – Whether to allow extra command line arguments. If not provided, it defaults to the class attribute extra_args.

  • condition – The condition to check before running the task. If not provided, it defaults to the class attribute condition.

  • before – The tasks to run before this task. If not provided, it defaults to the class attribute before.

  • after – The tasks to run after this task. If not provided, it defaults to the class attribute after.

  • cleanup – The tasks to run at the end, even if the task, or before or after tasks fail. If not provided, it defaults to the class attribute cleanup.

  • watch_paths – Directories to watch. If not provided, it defaults to the class attribute watch_paths.

  • watch_ignore_paths – Directory paths to ignore. If not provided, it defaults to the class attribute watch_ignore_paths.

  • watch_patterns – Patterns for changed files. If not provided, it defaults to the class attribute watch_patterns.

  • watch_ignore_patterns – Patterns to ignore. If not provided, it defaults to the class attribute watch_ignore_patterns.

  • watch_debounce – Debounce seconds for watch mode. If not provided, it defaults to the class attribute watch_debounce.

Methods

__init__([name, aliases, private, wraps, ...])

Initialize the task.

add_args(parser)

Add arguments to the parser.

condition_passes(*args, **kwargs)

Check the condition before running the task.

full_run(*args, **kwargs)

Execute the full task lifecycle and return the result of run().

get_after(*args, **kwargs)

Get the tasks to run after this task.

get_before(*args, **kwargs)

Get the tasks to run before this task.

get_cleanup(*args, **kwargs)

Get the tasks to run after this task, even if it fails.

get_help()

Get the help message of the task.

get_parser(*[, name])

Get the parser for the task.

get_plain_usage()

Return the usage string without ANSI escape sequences.

get_short_help()

Get the short help message of the task.

get_watch_config(*args, **kwargs)

Return watch mode configuration for this task.

log_task_execution(*args, **kwargs)

Log information about the task execution.

log_task_execution_details(*args, **kwargs)

Log details about the task execution.

parse_and_run(args)

Parse arguments and run the task.

parse_args(*, parser, args, extra_args)

Parse arguments.

run(*args, **kwargs)

Run the main work of this task.

run_after(*args, **kwargs)

Run the tasks after this task.

run_before(*args, **kwargs)

Run the tasks before this task.

run_cleanup(*args, **kwargs)

Run the tasks after this task, even if it fails.

to_info_dict(cwd)

Serialise task metadata to a plain dict suitable for JSON output.

Attributes

after

Tasks to run after this task.

args

Arguments for the task.

before

Tasks to run before this task.

cleanup

Tasks to run at the end, even if the task, or before or after tasks fail.

condition

The condition to check before running the task.

extra_args

Whether to allow extra command line arguments.

parser

Parser for the task.

watch_debounce

Seconds to wait after a file change before re-running.

watch_ignore_paths

Default directory paths to ignore when --watch is used.

watch_ignore_patterns

Default patterns to ignore when --watch is used.

watch_paths

Default directories to watch when --watch is used.

watch_patterns

Default patterns for changed files when --watch is used.

watch_recursive

Whether watch mode observes directories recursively.