Invoking pytask#

You can invoke pytask on the command line with

$ pytask

Use the following flags to learn more about pytask and its configuration.

$ pytask --version
$ pytask -h | --help

Commands#

pytask has multiple commands that are listed on the main help page.

$ pytask --help

<center>pytask v0.4.0</center>
Usage: <b>pytask [OPTIONS] [COMMAND] [PATHS]</b>

Manage your tasks with pytask.

<font color="#5f5f5f">╭─</font> Commands <font color="#5f5f5f">─────────────────────────────────────────────────────────────────╮</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">build *</span> Collect tasks, execute them and report the results.                <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font>                                                                            <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font>         This is pytask&#x27;s default command. pytask collects tasks from the   <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font>         given paths or the current working directory, executes them        <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font>         and reports the results.                                           <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">clean  </span> Clean the provided paths by removing files unknown to pytask.      <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">collect</span> Collect tasks and report information about them.                   <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">dag    </span> Create a visualization of the project&#x27;s directed acyclic graph.    <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">markers</span> Show all registered markers.                                       <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-command">profile</span> Show information about tasks like runtime and memory consumption   <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font>         of products.                                                       <font color="#5f5f5f">│</font>
<font color="#5f5f5f">╰────────────────────────────────────────────────────────────────────────────╯</font>
<font color="#5f5f5f">╭─</font> Options <font color="#5f5f5f">──────────────────────────────────────────────────────────────────╮</font>
<font color="#5f5f5f">│</font>    <span class="termynal-option">--version</span>  Show the version and exit.                                   <font color="#5f5f5f">│</font>
<font color="#5f5f5f">│</font> <span class="termynal-switch">-h</span> <span class="termynal-option">--help</span>     Show this message and exit.                                  <font color="#5f5f5f">│</font>
<font color="#5f5f5f">╰────────────────────────────────────────────────────────────────────────────╯</font>
<p align="right"><font color="#cd3131">♥</font> <a style="color: #f2f2f2" href="https://pytask-dev.readthedocs.io">https://pytask-dev.readthedocs.io</a> </p>

The build command is the default command, meaning the following two calls are identical.

$ pytask
$ pytask build

To display command-specific information, use the help flag after the command.

$ pytask <command-name> -h/--help

The build command#

The build command accepts many options paths as positional arguments. If no paths are passed via the command line interface, pytask will look for the paths key in the configuration file. At last, pytask will collect tasks from the current working directory and subsequent folders.

You can also pass any number of paths of directories or modules to the program.

$ pytask path/to/task_module.py path/to/folder

Do not use paths to run a subset of tasks in your project. Use expressions instead. When pytask collects tasks from subpaths of your project, it cannot infer the whole structure of dependencies and products and might run your tasks with missing or outdated dependencies.

Options#

Here are a few selected options for the build command.

Showing errors immediately#

To show errors immediately when they occur, use

$ pytask --show-errors-immediately

It can be helpful when you have a long-running workflow but want feedback as soon as it is available.

Stopping after the first (N) failures#

To stop the build of the project after the first n failures, use

$ pytask -x | --stop-after-first-failure  # Stop after the first failure
$ pytask --max-failures 2                 # Stop after the second failure

Performing a dry-run#

You can do a dry run to see which tasks would be executed without executing them.

$ pytask --dry-run
──────────────────────────── Start pytask session ────────────────────────────
Platform: win32 -- Python <span style="color: var(--termynal-blue)">3.10.0</span>, pytask <span style="color: var(--termynal-blue)">0.4.0</span>, pluggy <span style="color: var(--termynal-blue)">1.0.0</span>
Root: C:\Users\pytask-dev\git\my_project
Collected <span style="color: var(--termynal-blue)">1</span> task.

┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━┓
┃ Task                                              ┃ Outcome ┃
┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━┩
│ <span class="termynal-dim">task_dry_run.py::</span>task_dry_run                     │ <span class="termynal-success">w</span>       │
└───────────────────────────────────────────────────┴─────────┘

<span class="termynal-dim">──────────────────────────────────────────────────────────────────────────────</span>
<span class="termynal-success">╭───────────</span> <span style="font-weight: bold;">Summary</span> <span class="termynal-success">──────────────╮</span>
<span class="termynal-success">│</span> <span style="font-weight: bold;"> 1  Collected task </span>              <span class="termynal-success">│</span>
<span class="termynal-success">│</span> <span class="termynal-success-textonly"> 1  Would be executed  (100.0%) </span> <span class="termynal-success">│</span>
<span class="termynal-success">╰──────────────────────────────────╯</span>
<span class="termynal-success">───────────────────────── Succeeded in 0.02 seconds ──────────────────────────</span>

Functional interface#

pytask also has a functional interface that is explained in this article.