|
4 | 4 |
|
5 | 5 | </p>
|
6 | 6 |
|
| 7 | +- [General](#general) |
| 8 | +- [Requirements](#requirements) |
| 9 | +- [Usage](#usage) |
| 10 | + * [Installation](#installation) |
| 11 | + * [Adding Tasks](#adding-tasks) |
| 12 | + * [Running Tasks](#running-tasks) |
| 13 | + * [Passing Command Line Args to Tasks](#passing-command-line-args-to-tasks) |
| 14 | + * [Composing Tasks](#composing-tasks) |
| 15 | + * [Using Variables](#using-variables) |
| 16 | + * [Using Taskipy Without Poetry](#using-taskipy-without-poetry) |
| 17 | + * [Advanced Use Cases](#advanced-use-cases) |
| 18 | +- [Maintainers 🚧](#maintainers---) |
| 19 | +- [Contributors ✨](#contributors--) |
| 20 | + |
7 | 21 | ## General
|
8 | 22 | [](https://pypi.org/project/taskipy/)
|
9 | 23 | [](https://github.com/illBeRoy/taskipy/actions?query=workflow%3A%22Taskipy+Test+CI%22)
|
@@ -159,6 +173,53 @@ lint = "pylint tests taskipy"
|
159 | 173 |
|
160 | 174 | 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.
|
161 | 175 |
|
| 176 | +### Using Variables |
| 177 | +In some cases, you might find yourself passing the same arguments over and over again. Let us take a look at the following tasks: |
| 178 | + |
| 179 | +```toml |
| 180 | +[tool.taskipy.tasks] |
| 181 | +lint = "pylint path/to/my_module" |
| 182 | +black = "black path/to/my_module" |
| 183 | +``` |
| 184 | + |
| 185 | +As you can see, we provide the same path argument to both `pylint` and `black`. |
| 186 | + |
| 187 | +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: |
| 188 | + |
| 189 | +```toml |
| 190 | +[tool.taskipy.variables] |
| 191 | +path = "path/to/my_module" |
| 192 | + |
| 193 | +[tool.taskipy.tasks] |
| 194 | +lint = { cmd = "pylint {path}", use_vars = true } |
| 195 | +black = { cmd = "pylint {path}", use_vars = true } |
| 196 | +``` |
| 197 | + |
| 198 | +We have made the following changes to our configuration: |
| 199 | +1. We declared variables under `tool.taskipy.variables` |
| 200 | +2. We flagged the relevant task using `use_vars` to note that they should use the variables |
| 201 | +3. We replaced the repeating path with a `{path}` variable |
| 202 | + |
| 203 | +#### String Formatting |
| 204 | +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. |
| 205 | + |
| 206 | +#### Always Use Variables |
| 207 | +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. |
| 208 | + |
| 209 | +If you want to turn on `use_vars` globally, all you need to do is to declare that under taskipy's **settings** table: |
| 210 | + |
| 211 | +```toml |
| 212 | +[tool.taskipy.settings] |
| 213 | +use_vars = true |
| 214 | + |
| 215 | +[tool.taskipy.variables] |
| 216 | +path = "path/to/my_module" |
| 217 | + |
| 218 | +[tool.taskipy.tasks] |
| 219 | +lint = "pylint {path}" |
| 220 | +black = "black {path}" |
| 221 | +``` |
| 222 | + |
162 | 223 | ### Using Taskipy Without Poetry
|
163 | 224 | 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 eithout poetry:
|
164 | 225 |
|
|
0 commit comments