Building a Task Runner In Python

Building a Task Runner In Python

Yasta, your new task runner! ๐Ÿš

ยท

2 min read

Table of contents

In this article, I will talk about my most recent project, "Yasta".

Yasta is a modern task runner written in Python. ๐Ÿš

Yasta makes running and managing your tasks a breeze! ๐ŸŒฌ๏ธ

Even though it's written in Python, you can use it for any kind of project, or no projects at all!

I use it to automate some non-programming-related tasks on my machine.

For this project, I used Typer to build the CLI.

Yasta has 5 commands:

  1. init
    • Initializes the projects by creating a toml file, named pyproject.toml by default, and adds an empty test command.
  2. show
    • Shows the list of tasks and their commands
  3. add
    • Adds a task to the task list.
  4. run
    • Runs the specified task.
  5. delete
    • deletes the specified task.

run

"run" is probably the most interesting command.

image.png

path

The path option specifies the path for the tasks file. This is useful if your file is not named "pyproject.toml" or is in another directory.

The capture-output specifies whether you want to wait for the task to finish or not. For example, if one of your tasks is running takes a bit of time, and logs some information, then capturing output will wait for the process to end to show, which might not be what you want, in that case, you shouldn't use this option. However, if your tasks are short, you should use this option, which will capture the output, print its status in pretty colors, and show a table of the commands and the corresponding errors (if any!).

You can see the difference in the following image.

image.png

force

The force option is useful when you're running a list of tasks and you don't want a failing task to stop the rest of the tasks from running.

image.png

parallel

The parallel option runs a task that consists of several tasks, in parallel.

This is useful if you're running a task that runs 2 web servers, if you don't use the option, in this case, the second web server will be waiting until the first one ends.

That's it! The code base is quite small actually, but it serves all my needs pretty well.

Source code: github.com/adhamsalama/yasta

It was a delight using Typer to create this CLI. I would recommend it if you're writing a CLI in Python.

ย