taskipy


Nametaskipy JSON
Version 1.14.0 PyPI version JSON
download
home_pagehttps://github.com/taskipy/taskipy
Summarytasks runner for python projects
upload_time2024-10-23 13:04:16
maintainerNone
docs_urlNone
authorRoy Sommer
requires_python<4.0,>=3.6
licenseMIT
keywords tasks task runner development
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <p align="center">
  <img src="https://github.com/illBeRoy/taskipy/raw/master/logo.svg" width="150" />
</p>

- [General](#general)
- [Requirements](#requirements)
- [Usage](#usage)
  - [Installation](#installation)
  - [Adding Tasks](#adding-tasks)
  - [Running Tasks](#running-tasks)
  - [Passing Command Line Args to Tasks](#passing-command-line-args-to-tasks)
  - [Composing Tasks](#composing-tasks)
    - [Grouping Subtasks Together](#grouping-subtasks-together)
    - [Pre Task Hook](#pre-task-hook)
    - [Post Task Hook](#post-task-hook)
  - [Using Variables](#using-variables)
    - [String Formatting](#string-formatting)
    - [Always Use Variables](#always-use-variables)
    - [Recursive Variables](#recursive-variables)
  - [Working directory](#working-directory)
  - [Using Taskipy Without Poetry](#using-taskipy-without-poetry)
    - [Installing With PIP](#installing-with-pip)
    - [Running Tasks](#running-tasks-1)
  - [Advanced Use Cases](#advanced-use-cases)
- [Contribution](#contribution)

## General

[![pypi](https://img.shields.io/pypi/v/taskipy?style=flat-square)](https://pypi.org/project/taskipy/)
[![pypi-downloads](https://img.shields.io/pypi/dm/taskipy?style=flat-square)](https://pypi.org/project/taskipy/)
[![Conda Version](https://img.shields.io/conda/vn/conda-forge/taskipy.svg)](https://anaconda.org/conda-forge/taskipy)
[![ci](https://img.shields.io/github/actions/workflow/status/taskipy/taskipy/ci.yml?style=flat-square)](https://github.com/taskipy/taskipy/actions/workflows/ci.yml)

**The complementary task runner for python.**

Every development pipeline has tasks, such as `test`, `lint` or `publish`. With taskipy, you can define those tasks in one file and run them with a simple command.

For instance, instead of running the following command:

```bash
python -m unittest tests/test_*.py
```

You can create a task called `test` and simply run:

```bash
poetry run task test
```

Or (if you're not using poetry):

```bash
task test
```

In addition, you can compose tasks and group them together, and also create dependencies between them.

This project is heavily inspired by npm's [run script command](https://docs.npmjs.com/cli/run-script).

## Requirements

Python 3.6 or newer.

Your project directory should include a valid `pyproject.toml` file, as specified in [PEP-518](https://www.python.org/dev/peps/pep-0518/).

## Usage

### Installation

To install taskipy as a dev dependency, simply run:

```bash
poetry add --dev taskipy
```

For Anaconda Python-based environments, taskipy is also available via conda-forge:

```bash
conda install -c conda-forge taskipy
```

### Adding Tasks

In your `pyproject.toml` file, add a new section called `[tool.taskipy.tasks]`.

The section is a key-value map, from the names of the task to the actual command that should be run in the shell.

There are two ways to define tasks. The easy way is to simply write the command down as a string:

__pyproject.toml__

```toml
[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"
lint = "pylint tests taskipy"
```

Alternatively, you can define tasks more explicitly by declaring both the command and a helpful description using an inline table:

__pyproject.toml__

```toml
[tool.taskipy.tasks]
test = { cmd = "python -m unittest tests/test_*.py", help = "runs all unit tests" }
lint = { cmd = "pylint tests taskipy", help = "confirms code style using pylint" } 
```

The explicit notation is more verbose, but provides better context to anyone who uses the task.

### Running Tasks

In order to run a task, run the following command in your terminal:

```bash
$ poetry run task test
```

You can also list all existing tasks by running the following:

```bash
$ poetry run task --list
test                python -m unittest tests/test_*.py
lint                pylint tests taskipy
```

If you declared your task explicitly, you will see the description of the task by the side of the task's name:

```bash
$ poetry run task --list
test                runs all unit tests
lint                confirms code style using pylint
```

### Passing Command Line Args to Tasks

If you want to pass command line arguments to tasks (positional or named), simply append them to the end of the task command.

For example, running the above task like this:

```bash
poetry run task test -h
```

Is equivalent to running:

```bash
python -m unittest tests/test_*.py -h
```

And will show unittest's help instead of actually running it.

> ⚠️ Note: if you are using pre \ post hooks, do notice that arguments are not passed to them, only to the task itself.

### Composing Tasks

#### Grouping Subtasks Together

Some tasks are composed of multiple subtasks. Instead of writing plain shell commands and stringing them together, you can break them down into multiple subtasks:

```toml
[tool.taskipy.tasks]
lint_pylint = "pylint tests taskipy"
lint_mypy = "mypy tests taskipy"
```

And then create a composite task:

```toml
[tool.taskipy.tasks]
lint = "task lint_pylint && task lint_mypy"
lint_pylint = "pylint tests taskipy"
lint_mypy = "mypy tests taskipy"
```

#### Pre Task Hook

Tasks might also depend on one another. For example, tests might require some binaries to be built. Take the two following commands, for instance:

```toml
[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"
build = "make ."
```

You could make tests depend on building, by using the **pretask hook**:

```toml
[tool.taskipy.tasks]
pre_test = "task build"
test = "python -m unittest tests/test_*.py"
build = "make ."
```

The pretask hook looks for `pre_<task_name>` task for a given `task_name`. It will run it before running the task itself. If the pretask fails, then taskipy will exit without running the task itself.

#### Post Task Hook

From time to time, you might want to run a task in conjunction with another. For example, you might want to run linting after a successful test run. Take the two following commands, for instance:

```toml
[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"
lint = "pylint tests taskipy"
```

You could make tests trigger linting, by using the **posttask hook**:

```toml
[tool.taskipy.tasks]
test = "python -m unittest tests/test_*.py"
post_test = "task lint"
lint = "pylint tests taskipy"
```

The posttask hook looks for `post_<task_name>` task for a given `task_name`. It will run it after running the task itself. If the task failed, then taskipy will not run the posttask hook.

### Using Variables

In some cases, you might find yourself passing the same arguments over and over again. Let us take a look at the following tasks:

```toml
[tool.taskipy.tasks]
lint = "pylint path/to/my_module"
black = "black path/to/my_module"
```

As you can see, we provide the same path argument to both `pylint` and `black`.

In order to encourage DRY and improve your ability to change these values later on, taskipy actually lets you declare and reuse variables in your tasks:

```toml
[tool.taskipy.variables]
path = "path/to/my_module"

[tool.taskipy.tasks]
lint = { cmd = "pylint {path}", use_vars = true }
black = { cmd = "pylint {path}", use_vars = true }
```

We have made the following changes to our configuration:

1. We declared variables under `tool.taskipy.variables`
2. We flagged the relevant task using `use_vars` to note that they should use the variables
3. We replaced the repeating path with a `{path}` variable

#### String Formatting

The formatting of the task commands uses python's own `string.format` method, and therefore supports everything that python's [formatted string literals](https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals) let you do.

#### Always Use Variables

Using variables is opt-in, which means that by default commands do **not** use them, and you will have to turn them on a task to task basis.

If you want to turn on `use_vars` globally, all you need to do is to declare that under taskipy's **settings** table:

```toml
[tool.taskipy.settings]
use_vars = true

[tool.taskipy.variables]
path = "path/to/my_module"

[tool.taskipy.tasks]
lint = "pylint {path}"
black = "black {path}"
```

#### Recursive Variables

If we want to use variables within other variables, we can utilize recursive variables. By default, variables are not recursive, but we can specify a variable to be recursive by setting the `recursive` key to `true`.

```toml
[tool.taskipy.settings]
use_vars = true

[tool.taskipy.variables]
src_dir = "src"
package_dir = { var = "{src_dir}/package", recursive = true }

[tool.taskipy.tasks]
echo = "echo {package_dir}"
```

In this example, we could run `task echo` and we would then see `src/package`.

### Working directory

By default, all tasks run from the directory where they are called. This makes possible to change folder and run flexible tasks depending on the current folder.

However, some tasks may need to always run in the same working directory, regardless from where they are called.

If you want tasks to always run relative to a specific path, you can use the `"cwd"` setting to define a current working directory of the task relative to the root of the project (where the `pyproject.toml` file is):

```toml
[tool.taskipy.tasks]
echo = { cmd = "python -c \"import os; print(os.getcwd())\"" , cwd = "."}
```

In this example, running `task echo` will print the directory path of the file `pyproject.toml` regardless of the folder that you call this task.

If you want to define `cwd` globally (setting all tasks to always run from the same working directory) you just need to declare that under taskipy's **settings** table:

```toml
[tool.taskipy.settings]
cwd = "."
```

### Using Taskipy Without Poetry

Taskipy was created with poetry projects in mind, but actually only requires a valid `pyproject.toml` file in your project's directory. As a result, you can use it even without poetry:

#### Installing With PIP

Install taskipy on your machine or in your virtualenv using:

```bash
pip install taskipy
```

#### Running Tasks

Head into your project's directory (don't forget to activate virtualenv if you're using one), and run the following command:

```bash
task TASK
```

Where `TASK` is the name of your task.

### Advanced Use Cases

If you have a more specific use case, you might not be the first to run into it! Head over to the [ADVANCED_FEATURES](./docs/ADVANCED_FEATURES.md) doc, and look it up.

## Contribution

All kinds of contributions are welcome! Feel free to request features and report bugs via issues, and contribute your own beautiful code via pull requests!

The taskipy project is maintained by [Roy Sommer](https://github.com/illBeRoy). If you're interested in joining the team, feel free to let me know!

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/taskipy/taskipy",
    "name": "taskipy",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.6",
    "maintainer_email": null,
    "keywords": "tasks, task runner, development",
    "author": "Roy Sommer",
    "author_email": "roy@sommer.co.il",
    "download_url": "https://files.pythonhosted.org/packages/3f/bb/9ec5dab0707e61683d983527adc511e7fbc17fe1ca943c5f3adc3998105a/taskipy-1.14.0.tar.gz",
    "platform": null,
    "description": "<p align=\"center\">\n  <img src=\"https://github.com/illBeRoy/taskipy/raw/master/logo.svg\" width=\"150\" />\n</p>\n\n- [General](#general)\n- [Requirements](#requirements)\n- [Usage](#usage)\n  - [Installation](#installation)\n  - [Adding Tasks](#adding-tasks)\n  - [Running Tasks](#running-tasks)\n  - [Passing Command Line Args to Tasks](#passing-command-line-args-to-tasks)\n  - [Composing Tasks](#composing-tasks)\n    - [Grouping Subtasks Together](#grouping-subtasks-together)\n    - [Pre Task Hook](#pre-task-hook)\n    - [Post Task Hook](#post-task-hook)\n  - [Using Variables](#using-variables)\n    - [String Formatting](#string-formatting)\n    - [Always Use Variables](#always-use-variables)\n    - [Recursive Variables](#recursive-variables)\n  - [Working directory](#working-directory)\n  - [Using Taskipy Without Poetry](#using-taskipy-without-poetry)\n    - [Installing With PIP](#installing-with-pip)\n    - [Running Tasks](#running-tasks-1)\n  - [Advanced Use Cases](#advanced-use-cases)\n- [Contribution](#contribution)\n\n## General\n\n[![pypi](https://img.shields.io/pypi/v/taskipy?style=flat-square)](https://pypi.org/project/taskipy/)\n[![pypi-downloads](https://img.shields.io/pypi/dm/taskipy?style=flat-square)](https://pypi.org/project/taskipy/)\n[![Conda Version](https://img.shields.io/conda/vn/conda-forge/taskipy.svg)](https://anaconda.org/conda-forge/taskipy)\n[![ci](https://img.shields.io/github/actions/workflow/status/taskipy/taskipy/ci.yml?style=flat-square)](https://github.com/taskipy/taskipy/actions/workflows/ci.yml)\n\n**The complementary task runner for python.**\n\nEvery development pipeline has tasks, such as `test`, `lint` or `publish`. With taskipy, you can define those tasks in one file and run them with a simple command.\n\nFor instance, instead of running the following command:\n\n```bash\npython -m unittest tests/test_*.py\n```\n\nYou can create a task called `test` and simply run:\n\n```bash\npoetry run task test\n```\n\nOr (if you're not using poetry):\n\n```bash\ntask test\n```\n\nIn addition, you can compose tasks and group them together, and also create dependencies between them.\n\nThis project is heavily inspired by npm's [run script command](https://docs.npmjs.com/cli/run-script).\n\n## Requirements\n\nPython 3.6 or newer.\n\nYour project directory should include a valid `pyproject.toml` file, as specified in [PEP-518](https://www.python.org/dev/peps/pep-0518/).\n\n## Usage\n\n### Installation\n\nTo install taskipy as a dev dependency, simply run:\n\n```bash\npoetry add --dev taskipy\n```\n\nFor Anaconda Python-based environments, taskipy is also available via conda-forge:\n\n```bash\nconda install -c conda-forge taskipy\n```\n\n### Adding Tasks\n\nIn your `pyproject.toml` file, add a new section called `[tool.taskipy.tasks]`.\n\nThe section is a key-value map, from the names of the task to the actual command that should be run in the shell.\n\nThere are two ways to define tasks. The easy way is to simply write the command down as a string:\n\n__pyproject.toml__\n\n```toml\n[tool.taskipy.tasks]\ntest = \"python -m unittest tests/test_*.py\"\nlint = \"pylint tests taskipy\"\n```\n\nAlternatively, you can define tasks more explicitly by declaring both the command and a helpful description using an inline table:\n\n__pyproject.toml__\n\n```toml\n[tool.taskipy.tasks]\ntest = { cmd = \"python -m unittest tests/test_*.py\", help = \"runs all unit tests\" }\nlint = { cmd = \"pylint tests taskipy\", help = \"confirms code style using pylint\" } \n```\n\nThe explicit notation is more verbose, but provides better context to anyone who uses the task.\n\n### Running Tasks\n\nIn order to run a task, run the following command in your terminal:\n\n```bash\n$ poetry run task test\n```\n\nYou can also list all existing tasks by running the following:\n\n```bash\n$ poetry run task --list\ntest                python -m unittest tests/test_*.py\nlint                pylint tests taskipy\n```\n\nIf you declared your task explicitly, you will see the description of the task by the side of the task's name:\n\n```bash\n$ poetry run task --list\ntest                runs all unit tests\nlint                confirms code style using pylint\n```\n\n### Passing Command Line Args to Tasks\n\nIf you want to pass command line arguments to tasks (positional or named), simply append them to the end of the task command.\n\nFor example, running the above task like this:\n\n```bash\npoetry run task test -h\n```\n\nIs equivalent to running:\n\n```bash\npython -m unittest tests/test_*.py -h\n```\n\nAnd will show unittest's help instead of actually running it.\n\n> \u26a0\ufe0f Note: if you are using pre \\ post hooks, do notice that arguments are not passed to them, only to the task itself.\n\n### Composing Tasks\n\n#### Grouping Subtasks Together\n\nSome tasks are composed of multiple subtasks. Instead of writing plain shell commands and stringing them together, you can break them down into multiple subtasks:\n\n```toml\n[tool.taskipy.tasks]\nlint_pylint = \"pylint tests taskipy\"\nlint_mypy = \"mypy tests taskipy\"\n```\n\nAnd then create a composite task:\n\n```toml\n[tool.taskipy.tasks]\nlint = \"task lint_pylint && task lint_mypy\"\nlint_pylint = \"pylint tests taskipy\"\nlint_mypy = \"mypy tests taskipy\"\n```\n\n#### Pre Task Hook\n\nTasks might also depend on one another. For example, tests might require some binaries to be built. Take the two following commands, for instance:\n\n```toml\n[tool.taskipy.tasks]\ntest = \"python -m unittest tests/test_*.py\"\nbuild = \"make .\"\n```\n\nYou could make tests depend on building, by using the **pretask hook**:\n\n```toml\n[tool.taskipy.tasks]\npre_test = \"task build\"\ntest = \"python -m unittest tests/test_*.py\"\nbuild = \"make .\"\n```\n\nThe pretask hook looks for `pre_<task_name>` task for a given `task_name`. It will run it before running the task itself. If the pretask fails, then taskipy will exit without running the task itself.\n\n#### Post Task Hook\n\nFrom time to time, you might want to run a task in conjunction with another. For example, you might want to run linting after a successful test run. Take the two following commands, for instance:\n\n```toml\n[tool.taskipy.tasks]\ntest = \"python -m unittest tests/test_*.py\"\nlint = \"pylint tests taskipy\"\n```\n\nYou could make tests trigger linting, by using the **posttask hook**:\n\n```toml\n[tool.taskipy.tasks]\ntest = \"python -m unittest tests/test_*.py\"\npost_test = \"task lint\"\nlint = \"pylint tests taskipy\"\n```\n\nThe posttask hook looks for `post_<task_name>` task for a given `task_name`. It will run it after running the task itself. If the task failed, then taskipy will not run the posttask hook.\n\n### Using Variables\n\nIn some cases, you might find yourself passing the same arguments over and over again. Let us take a look at the following tasks:\n\n```toml\n[tool.taskipy.tasks]\nlint = \"pylint path/to/my_module\"\nblack = \"black path/to/my_module\"\n```\n\nAs you can see, we provide the same path argument to both `pylint` and `black`.\n\nIn order to encourage DRY and improve your ability to change these values later on, taskipy actually lets you declare and reuse variables in your tasks:\n\n```toml\n[tool.taskipy.variables]\npath = \"path/to/my_module\"\n\n[tool.taskipy.tasks]\nlint = { cmd = \"pylint {path}\", use_vars = true }\nblack = { cmd = \"pylint {path}\", use_vars = true }\n```\n\nWe have made the following changes to our configuration:\n\n1. We declared variables under `tool.taskipy.variables`\n2. We flagged the relevant task using `use_vars` to note that they should use the variables\n3. We replaced the repeating path with a `{path}` variable\n\n#### String Formatting\n\nThe formatting of the task commands uses python's own `string.format` method, and therefore supports everything that python's [formatted string literals](https://docs.python.org/3/tutorial/inputoutput.html#formatted-string-literals) let you do.\n\n#### Always Use Variables\n\nUsing variables is opt-in, which means that by default commands do **not** use them, and you will have to turn them on a task to task basis.\n\nIf you want to turn on `use_vars` globally, all you need to do is to declare that under taskipy's **settings** table:\n\n```toml\n[tool.taskipy.settings]\nuse_vars = true\n\n[tool.taskipy.variables]\npath = \"path/to/my_module\"\n\n[tool.taskipy.tasks]\nlint = \"pylint {path}\"\nblack = \"black {path}\"\n```\n\n#### Recursive Variables\n\nIf we want to use variables within other variables, we can utilize recursive variables. By default, variables are not recursive, but we can specify a variable to be recursive by setting the `recursive` key to `true`.\n\n```toml\n[tool.taskipy.settings]\nuse_vars = true\n\n[tool.taskipy.variables]\nsrc_dir = \"src\"\npackage_dir = { var = \"{src_dir}/package\", recursive = true }\n\n[tool.taskipy.tasks]\necho = \"echo {package_dir}\"\n```\n\nIn this example, we could run `task echo` and we would then see `src/package`.\n\n### Working directory\n\nBy default, all tasks run from the directory where they are called. This makes possible to change folder and run flexible tasks depending on the current folder.\n\nHowever, some tasks may need to always run in the same working directory, regardless from where they are called.\n\nIf you want tasks to always run relative to a specific path, you can use the `\"cwd\"` setting to define a current working directory of the task relative to the root of the project (where the `pyproject.toml` file is):\n\n```toml\n[tool.taskipy.tasks]\necho = { cmd = \"python -c \\\"import os; print(os.getcwd())\\\"\" , cwd = \".\"}\n```\n\nIn this example, running `task echo` will print the directory path of the file `pyproject.toml` regardless of the folder that you call this task.\n\nIf you want to define `cwd` globally (setting all tasks to always run from the same working directory) you just need to declare that under taskipy's **settings** table:\n\n```toml\n[tool.taskipy.settings]\ncwd = \".\"\n```\n\n### Using Taskipy Without Poetry\n\nTaskipy was created with poetry projects in mind, but actually only requires a valid `pyproject.toml` file in your project's directory. As a result, you can use it even without poetry:\n\n#### Installing With PIP\n\nInstall taskipy on your machine or in your virtualenv using:\n\n```bash\npip install taskipy\n```\n\n#### Running Tasks\n\nHead into your project's directory (don't forget to activate virtualenv if you're using one), and run the following command:\n\n```bash\ntask TASK\n```\n\nWhere `TASK` is the name of your task.\n\n### Advanced Use Cases\n\nIf you have a more specific use case, you might not be the first to run into it! Head over to the [ADVANCED_FEATURES](./docs/ADVANCED_FEATURES.md) doc, and look it up.\n\n## Contribution\n\nAll kinds of contributions are welcome! Feel free to request features and report bugs via issues, and contribute your own beautiful code via pull requests!\n\nThe taskipy project is maintained by [Roy Sommer](https://github.com/illBeRoy). If you're interested in joining the team, feel free to let me know!\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "tasks runner for python projects",
    "version": "1.14.0",
    "project_urls": {
        "Homepage": "https://github.com/taskipy/taskipy",
        "Repository": "https://github.com/taskipy/taskipy"
    },
    "split_keywords": [
        "tasks",
        " task runner",
        " development"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "caf84ba612af0146981a46315adbd78d87dc6268b3a21d865d045956103661fe",
                "md5": "20278d0110a24a0045f32f3443b203cf",
                "sha256": "29040d9a8038170602feb71792bdef5203720ed30f595304aee843625892452b"
            },
            "downloads": -1,
            "filename": "taskipy-1.14.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "20278d0110a24a0045f32f3443b203cf",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.6",
            "size": 13052,
            "upload_time": "2024-10-23T13:04:15",
            "upload_time_iso_8601": "2024-10-23T13:04:15.352701Z",
            "url": "https://files.pythonhosted.org/packages/ca/f8/4ba612af0146981a46315adbd78d87dc6268b3a21d865d045956103661fe/taskipy-1.14.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3fbb9ec5dab0707e61683d983527adc511e7fbc17fe1ca943c5f3adc3998105a",
                "md5": "ce75ad050641a758fbb0daeb51f74bfe",
                "sha256": "5d9631c29980481d59858f0a100ed3200cf7468ca8c0540ef19388586485532d"
            },
            "downloads": -1,
            "filename": "taskipy-1.14.0.tar.gz",
            "has_sig": false,
            "md5_digest": "ce75ad050641a758fbb0daeb51f74bfe",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.6",
            "size": 14468,
            "upload_time": "2024-10-23T13:04:16",
            "upload_time_iso_8601": "2024-10-23T13:04:16.991389Z",
            "url": "https://files.pythonhosted.org/packages/3f/bb/9ec5dab0707e61683d983527adc511e7fbc17fe1ca943c5f3adc3998105a/taskipy-1.14.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-23 13:04:16",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "taskipy",
    "github_project": "taskipy",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "taskipy"
}
        
Elapsed time: 4.35070s