Skip to main content

Test

What is this?

Taskrunner (henceforth, TR) allows users to run tasks with relation to the current working directory. Somewhat similar to VScode tasks, TR tasks are not bound to a specific platform and can be invoked from anywhere. A trivial environment for TR is a shell console, but any environment with ability to run executables is suitable.

One can think of TR as a commands repository for a directory or a way to enable dynamic PATH, where commands become available and unavailable according to the working directory.

TR was written as a successor to runenv, a tool I wrote for running containers commands in similar manner which was extremely popular between myself and a guy I knew from work. runenv is great for sparing the user from remembering container settings for a given command, but is limited for a single task, isn't built for tasks that aren't container based and has limited features.

Why do I need it?

Assume working on a project in a directory project-dir, where a long and complicated commands like: my-command -vv --with-this-flags --and-this-flag=5 THIS_ARG AND_THIS_ARG are often required. Remembering and repeating it can be annoying and time consuming.

One could rely on history, but commands history browsing can be as annoying as typing it. Besides, after a long period of time, the required entry might not even be there, and if another user needs it, he needs to figure it out on his own.

Using shell script is a possible solution - place the logic in a script like my-task.sh and run it instead. This would work, of course, but now we need to remember my-task.sh and where it resides. Unless placed in the search PATH, it's not just a matter of running my-task but path/to/my-task. And again, if another user needs to run this command by herself, she has to have knowledge of this script in advance.

An alias approach can also be tried: Alias my-command-alias to our command. Again, this works but suffers from drawbacks: you are either bound to have the my-command available in PATH or have the entire project pinned to a given directory. In addition, aliases are user level entities: A different user or placing the project in a different machine will require redefining the alias for that login. And once again - we need to know and remember what aliases are relevant - there's no way to differentiate between project and global aliases.

The situation might get more complicated if other commands are needed as well - with other arguments, other working directories, maybe some environment variables, etc.

With TR, all these problems are solved. All that is required is a project level configuration file defining a task named my-task to run the horrible my-command... and the command becomes available all over the project hierarchy, to all users with access to the project. task list can be used to see what tasks are available and task info to understand what they are doing. As long as TR is installed, moving the project to another machine will provide all the tasks with it.

Installation and requirements

TR is python based tool, verified for python 3.11 and above. Older versions might work as well, but are not actively supported and packaged so manual install is required.

To install run pip3 install pytaskrunner.

For installation from source:

  1. Clone the repository
  2. Install the requirements using pip pip3 install <path to cloned repository>

TR should work for any environment with compatible python, however it is developed on and maintained for Linux machines. CI tests are run for MacOS as well without container support. It is known to work on Cygwin systems (again, without containers support).

Basic configuration and usage

TR uses yaml or json configuration files (By default, named .tasks.yaml) to describe tasks. These tasks are available when the current work directory is anywhere in the directory hierarchy under the directory the configuration file was placed in - TR recursively looks for .tasks.yaml from the current working directory up to root.

Once set, use the following commands:

  1. Running tasks - by running task run <TASK>
  2. Getting info on a task - by running task info <TASK>
  3. Listing available tasks - by running task list
  4. Exporting a task as shell commands - by running task export <TASK>

Configuration file search order

TR searches for configuration files in the following order:

  1. The current working directory, and recursively up to the root directory.
  2. The user's home directory, in the .config directory. In any of these directories, the first configuration file found is used. TR searches for the following files (in order): .tasks.yaml, tasks.yaml, .tasks.json and tasks.json.

Configuration files may include other files, as well as the default configuration file located in the user's home directory. By default, the default configuration file is included. This behaviour can be disabled by setting use_default_include to false.

Example - building projects

[source code projects are used in the following examples, but any sort of task is valid - scp some files, start a service through systemctl, open a video with vlc, etc.]:

Assume a cmake based project in a directory named cmake-project with lots of sub directories. It might look something like this:

user@host $ tree cmake-project
.
├── build
├── subdir0
├── subdir1
│   └── subdir3
│       └── subdir4
└── subdir5
    └── subdir6

Often running basic cmake commands in such environments requires:

  1. Entering the project's build directory
  2. Running cmake ..

Not very complicated, but can get tedious when actively developing cmake files all over the tree. By adding the following .tasks.yaml file into cmake-project directory, rerunning the relevant cmake command becomes a trivial one-liner:

tasks:
  cmake:
    short_desc: Run cmake
    description: Run 'cmake ..' for the cmake-project
    commands:
      - cmake ..
    cwd: '{{taskRoot}}/build'

Once set, running task run cmake from anywhere under cmake-project will run the cmake .. with cmake-project/build as the working directory.

In the tasks section our task, named cmake is defined:

  • short_desc and description are for documentation and self-explanatory.
  • commands sets a list of commands for this task to execute. In this case, a single cmake .. command is set.
  • cwd sets the working directory for this task. Its commands are executed with this setting value as their working directory. The {{taskRoot}} is an automatic variable with the value of the location of the configuration file. Using it in cwd allows moving the project around without the need to update it. In our case, if the configuration file is placed in cmake-project root, say, /home/user/projects/cmake-project, the expanded value is /home/user/projects/cmake-project/build.

To list the available tasks, run task list:

user@host $ task list
Name                                      Flags       Description
----                                      -----       -----------
cmake                                                 Run cmake

And for the task full details, run task info cmake, and add the -x flag for values expansion; in our case, the working directory:

user@host $ task info -x cmake
Task name:              cmake
Short description:      Run cmake
Description:            Run 'cmake ..' for the cmake-project
Hidden:                 No
Abstract:               No
Use shell:              No
Inherit environment:    Yes
Working directory:      /home/user/projects/cmake-project/build
Command:                cmake ..

Now lets assume there's a need to occasionally run another task, similar to the one already defined. For example, with some cmake definition like -DSOMEVAR=somevalue. And another task that actually builds the project with cmake --build .., both, like the first task, need to be invoked from the build directory (Again, if you don't care about cmake and source building, don't worry about what each command does. Anything can be used here). Instead of remembering each command or placing these in shell scripts and then trying to remember where they are, using TR tasks simplifies the workflow:

tasks:
  cmake:
    short_desc: Run cmake
    description: Run 'cmake ..' for the cmake-project
    commands:
      - cmake ..
    cwd: '{{taskRoot}}/build'
  cmake-with-def:
    short_desc: Run cmake with cmake define flag
    description: Run 'cmake ..' for the cmake-project, with a cmake define flag
    commands:
      - cmake -DSOMEVAR=somevalue ..
    cwd: '{{taskRoot}}/build'
  build:
    short_desc: Build the project
    description: Build the project using cmake's build command
    commands:
      - cmake --build ..
    cwd: '{{taskRoot}}/build'

And now all commands are available, from any directory under cmake-project:

user@host $ task list
Name                                      Flags       Description
----                                      -----       -----------
build                                                 Build the project
cmake                                                 Run cmake
cmake-with-def                                        Run cmake with cmake define flag

user@host $ task info build
Task name:              build
Short description:      Build the project
Description:            Build the project using cmake's build command
Hidden:                 No
Abstract:               No
Use shell:              No
Inherit environment:    Yes
Working directory:      {{taskRoot}}/build
Command:                cmake --build ..

user@host $ task run build
...

The above example can be further simplified by using variables and inheritance.

Multiple projects - same semantics, different details

Extending the example above, assume multiple projects, each with its own way of doing things. Let's say (based on true events), that other than the notorious cmake-project we have 2 additional projects named make-project and scons-project (and ninja-project and meson project etc...).

user@host $ tree projects
projects
├── cmake-project
├── make-project
└── scons-project

As these new projects name imply, they are built around make and scons build systems so their build process is different than our old cmake-project yet still we want to 'build' each one. We can try to remember each build command by our own and make sure we are in the correct project, or we can use TR: After adding a tasks file on each of these projects root directories each with its own build task, (like the build task shown for cmake-project) the user can just run task run build in any of these projects, and the correct build command will be invoked. If her environment is consistent, she might add an alias like (Bash style) alias build='task run build' for even easier build - and whenever inside any of the source projects directories, running build invokes the correct command for the current project.

Advanced usage

This section will describe some of advanced configuration and usage topics. For a detailed list of all configuration settings, refer to the configuration documentation

Variables

TR allows definitions of variables to be used throughout the configuration.

  • Variables are evaluated as strings.
  • A variable VAR can be referred as {{VAR}}
  • Variables can be used in the following task properties: commands, environment variables, current working directory, container image, container environment variables, container working directory and container volumes.
  • A variable can be defined using other variables

There are 3 types of variables with different priorities:

  1. Global variables - Defined in global level using variables as key word. They are available for every task with the scope of the tasks file's namespace.
  2. Task variables - Defined in task definition level using variables as key word. They are available for the task they are defined in and those inherit from it. Inherited variables are overridden by the inheriting task variables. All task variables override global variables with the same name.
  3. System variables - set by TR and will override any variables with the same name. The following variables are defined:
    • cwd - for the current working directory
    • taskRoot - for the path of the directory the found configuration file was found. This is helpful when a task needs to refer to a directory relatively to the project (see previous examples for its usage).
    • cliArgs - refers to arguments given by the user through CLI. See section about passing command CLI arguments

TR auto variables override any user variable, so avoid setting variables with reserved names.

The following example shows the different types of variables definition and usage.

variables:
  ENV_NAME: global_env_name
  ENV_VALUE: global_env_value
  var0: global_var0_value
  var1: global_var1_value
tasks:
  task0:
    variables:
      var1: task0_var1_value
      var2: task0_var2_value
    env:
      '{{ENV_NAME}}': '{{ENV_VALUE}}'
    commands:
      - printenv {{ENV_NAME}}
      - echo {{var0}}
      - echo {{var1}}
      - echo {{var2}}
  task1:
    base: task0
    variables:
      ENV_VALUE: task1_env_value
      var2: task1_var2_value
    env:
      '{{ENV_NAME}}': '{{ENV_VALUE}}'

In the above example, a few global vars are defined. task0 overrides the global var1 and sets its own var2. task1 overrides the inherited task0 var2. Note the environment variable setting using the TR variables. See the inheritance section for more details about task inheritance.

Environment variables

Environment variables can be referred with {{$VAR}}, where VAR is the variable name. Environment variables can be used wherever TR variables can be used. Note the difference between environment variables used in the task setting and environment variables that are set for a given task using the env keyword.

When a task is invoked its commands are invoked with the current set of system environment variables merged with task specific variables if such exist either from the task configuration or from CLI. Task variables take precedence over system variables. This behavior can be modified by setting the task's inherit_os_env. Set to false, TR ignores the system environment variables, and passes the task commands only the task environment variables. By default inherit_os_env is set to true.

Container based tasks

TR includes special support for running tasks inside a container. The main container setting is c_image defining a container image to use. The following task runs ls -l inside a container with a volume, CWD set, tty allocated, interactive mode, wrapped in a /bin/sh -c:

build:
  short_desc: Build
  c_image: localhost/media-builder:latest
  c_volumes:
    - '{{cwd}}:{{cwd}}'
  c_tty: true
  c_interactive: true
  c_shell: true
  c_cwd: '{{taskRoot}}'
  commands:
    - ls -l

The actual command the task invokes is /usr/bin/docker run -w {{taskRoot}} -i -t --rm -v {{cwd}}:{{cwd}} localhost/media-builder:latest /bin/sh -c "ls -l".

Container support is syntactic sugar, and putting the complete container command as a commands entry instead of setting a task container settings is completely valid and equivalent for having TR assemble the command instead, but usually it's much easier to let TR handle these settings.

For a detailed list of all container configuration settings, refer to the configuration documentation.

Inheritance

A task might inherit another task settings by using the base settings. If task a inherits task b, all of b's settings are inherited. Settings redefined in task a will override inherited settings. The exceptions are hidden and abstract, which are never inherited, and commands, env, variables, c_env and c_volumes, which are combined with the base task's values (see base_cmds and the inherit_* settings in the configuration documentation). The following example demonstrates how to utilize task inheritance for creating multiple tasks with similar characteristics that differ in small details (working directory):

tasks:
  base-task:
    abstract: true
    commands:
      - very_complicated command --with --lots=of --flags and arguments
    env:
      and: some
      environment: variables
  task-1:
    base: base-task
    cwd: /opt/task-1_dir
  task-2:
    base: base-task
    cwd: /opt/task-2_dir

Configuration files inclusion

Every configuration file can include multiple files using a global include setting. Variables and tasks are included, and overridden if they exist in a following include file, and finally in the original configuration file. Other global settings are taken only from the original configuration file.

A special file located in ${HOME}/.config/ (named .tasks.yaml, tasks.yaml, .tasks.json or tasks.json) is included by default if it exists. This behavior can be disabled by setting use_default_include to false.

Namespaces

Included files may define tasks and variables with the same names as other files, without overriding each other, by setting a namespace. Every file's tasks and global variables belong to its namespace, and files without one belong to the __DEFAULT__ namespace. Several files may share a namespace, in which case their tasks and variables override each other as described above. Task and variable names can't contain ..

Tasks are referred to as [NAMESPACE.]NAME:

  • In configuration files (base, suppress), a name without a namespace refers to a task in the namespace of the file it's written in, even when the task is inherited by a task from another namespace.
  • In the command line (and default_task), a name without a namespace refers to the tasks of the configuration file TR found or was given, or to __DEFAULT__ tasks it doesn't hide. task list shows these tasks without a namespace, and all others with one. __DEFAULT__ tasks hidden by the configuration file's tasks are only listed with task list --force-default-ns, but can always be run as __DEFAULT__.NAME.
  • As always, a unique prefix of a task's name can be used, within the referred namespace.

Global variables are looked up in the namespace each setting was written in. A command written in namespace lib expands {{out}} with lib's out, even when it's inherited by a task from another namespace, and {{lib.out}} can be used anywhere. Task variables still override global variables, so inheriting tasks can customize their base tasks through them.

# lib.yaml
namespace: lib
variables:
  out: /tmp/lib
tasks:
  build:
    commands:
      - make -C {{out}}
# .tasks.yaml
include:
  - '{{taskRoot}}/lib.yaml'
variables:
  out: /tmp/project
tasks:
  build:
    commands:
      - make -C {{out}}  # /tmp/project
  build-all:
    base: lib.build      # make -C /tmp/lib, then:
    base_cmds: before
    commands:
      - make -C {{out}}  # /tmp/project

task run build runs the project's build, and task run lib.build runs the included one.

Passing command line arguments to commands

Command line arguments are transferred to a task run with the -- convention: text written after the 'dash dash' token is transferred as arguments. The arguments aren't passed to the commands automatically. In order for a command to use CLI arguments, it must explicitly use it with the {{cliArgs}} variable. This allows fine grain control of which commands and where inside the command the CLI arguments are used. In fact, since arguments are translated to a TR variable, {{cliArgs}} can be used in every setting with variables support. Running task run ls -- -l somefile.txt in the following task will run ls -l somefile.txt:

ls:
  commands:
    - ls {{cliArgs}}
  short_desc: List files

TR CLI options

TR allows overriding almost any configuration setting using the CLI. In general these should be avoided unless debugging or tweaking a task temporarily. For example, if one wants to run a task but just tweak the command it runs (retaining other settings like container settings, environment variable, etc.), running task run -c "my new command" <TASK> will do the trick.

Run task -h and task <CMD> -h for the full list of CLI options.

Exporting tasks as shell commands

task export <TASK> prints the shell commands a task would run, without running them: an export line for each of the task's environment variables, a cd to its working directory, and its commands with all variables expanded. Container based tasks are printed as complete container tool commands. Variables can be set with -V, as with task run. The output is meant for reviewing a task's commands. Note that the task's shell, stop_on_error and inherit_os_env settings aren't reflected in it; the commands run in whatever shell executes them, with its environment, and don't stop on errors.

To run a task where TR isn't installed, use task export --as-script <TASK> instead, which prints a complete bash script that behaves like task run:

  • Each command runs as TR would run it: through the task's shell if shell is set, or with the exact arguments TR would pass otherwise.
  • The script stops on the first failing command if stop_on_error is set, and otherwise runs all commands. Either way, it exits with the first failing command's exit code.
  • If the working directory can't be entered, the script exits with 255, like task run, without running any command.
  • Environment variables whose names aren't valid shell variable names can't be exported by a script, so exporting such a task fails.

The inherit_os_env setting isn't reflected in the script either: its commands always inherit the environment of the shell that runs it.

Bash completion

TR uses argcomplete for bash auto complete. See argcomplete documentation for more details.

Logging

TR Logging can be enabled with the --log_file <FILE> CLI option. Use -v to increase its verbosity.

Status

While tested and works, TR is still a work in progress. Breaking changes are expected. Configuration validation will issue error messages if an invalid or incompatible configuration is detected.

Metadata

Release files for pytaskrunner 0.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pytaskrunner 0.15
File Size Uploaded Provenance Actions
pytaskrunner-0.15.tar.gz 71.8 kB With provenance Details for pytaskrunner-0.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for pytaskrunner 0.15
File Interpreter ABI Platform Actions
pytaskrunner-0.15-py3-none-any.whl Python 3 none any Details for pytaskrunner-0.15-py3-none-any.whl

Total release size: 99.1 kB

Release files / pytaskrunner-0.15.tar.gz

Download URL pytaskrunner-0.15.tar.gz
Size 71.8 kB
Tags Source
SHA-256 checksum
How to use checksums
83619d543bf5c98c4ab3bf2a85df6a9115e1a5feb141a41111dc4fbe1db3bedb
BLAKE2b-256 checksum
How to use checksums
8a64e0268043c1adef518a13351feca99a8fce8addd5507863e8d56149bdfe87
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / pytaskrunner-0.15-py3-none-any.whl

Download URL pytaskrunner-0.15-py3-none-any.whl
Size 27.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a894010aa2db40c52cd48c27ede0b9d16475861148ca92cdeb107ab3ebe4d315
BLAKE2b-256 checksum
How to use checksums
7465bcee5c2635e1a518daa4cc9dd8664dfb40acc9be010e29775b10fd830d40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for pytaskrunner 0.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for pytaskrunner-0.15.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page