Skipping tasks#

Skipping tasks is one way to prevent tasks from being executed. It is more persistent but less dynamic than selecting tasks via markers or expressions.

In contrast to tasks in ignored files, ignored with ignore, pytask will still check whether skipped tasks are consistent with the DAG of the project.

For example, you can use the @pytask.mark.skip decorator to skip tasks during development that take too much time to compute right now.

# Content of task_create_dependency.py


@pytask.mark.skip
@pytask.mark.produces("time_intensive_product.pkl")
def task_long_running(produces):
    ...

Not only will this task be skipped, but all tasks that depend on time_intensive_product.pkl.

Conditional skipping#

In large projects, you may have many long-running tasks that you only want to execute on a remote server but not when you are not working locally.

In this case, use the @pytask.mark.skipif decorator, which requires a condition and a reason as arguments:

# Content of a config.py

NO_LONG_RUNNING_TASKS = True
# Content of task_create_dependency.py


@pytask.mark.produces("run_always.md")
def task_always(produces):
    ...
# Content of task_long_running.py

from config import NO_LONG_RUNNING_TASKS


@pytask.mark.skipif(NO_LONG_RUNNING_TASKS, reason="Skip long-running tasks.")
@pytask.mark.depends_on("time_intensive_product.pkl")
def task_that_takes_really_long_to_run(depends_on):
    ...

Further Reading#