| 1 |
.. meta:: |
| 2 |
:description: doit provides several sub-commands to introspect and manipulated defined tasks |
| 3 |
:keywords: python, doit, documentation, guide, task, list, auto, introspection |
| 4 |
|
| 5 |
.. title:: A survey of doit sub-commands for task manipulation |
| 6 |
|
| 7 |
|
| 8 |
================================== |
| 9 |
sub-commands for task manipulation |
| 10 |
================================== |
| 11 |
|
| 12 |
.. note:: |
| 13 |
|
| 14 |
Not all options/arguments are documented below. |
| 15 |
Always check `doit help <cmd>` to see a complete list of options. |
| 16 |
|
| 17 |
|
| 18 |
Let's use a more complex example to demonstrate the command line features. |
| 19 |
The example below is used to manage a very simple C project. |
| 20 |
|
| 21 |
|
| 22 |
.. literalinclude:: samples/cproject.py |
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
.. _cmd-help: |
| 27 |
|
| 28 |
help |
| 29 |
------- |
| 30 |
|
| 31 |
`doit` comes with several commands. `doit help` will list all available commands. |
| 32 |
|
| 33 |
You can also get help from each available command. e.g. `doit help run`. |
| 34 |
|
| 35 |
`doit help task` will display information on all fields/attributes a task dictionary from a `dodo` file accepts. |
| 36 |
|
| 37 |
|
| 38 |
.. _cmd-list: |
| 39 |
|
| 40 |
list |
| 41 |
------ |
| 42 |
|
| 43 |
*list* is used to show all tasks available in a *dodo* file. |
| 44 |
Tasks are listed in alphabetical order by default, but *--sort=definition* can |
| 45 |
be specified to sort them in the order in which they appear in the `dodo` file. |
| 46 |
|
| 47 |
.. code-block:: console |
| 48 |
|
| 49 |
$ doit list |
| 50 |
compile : compile C files |
| 51 |
install : install executable (TODO) |
| 52 |
link : create binary program |
| 53 |
|
| 54 |
|
| 55 |
By default task name and description are listed. The task description is taken |
| 56 |
from the first line of task function doc-string. You can also set it using the |
| 57 |
*doc* attribute on the task dictionary. It is possible to omit the description |
| 58 |
using the option *-q*/*--quiet*. |
| 59 |
|
| 60 |
By default sub-tasks are not listed. It can list sub-tasks using the option |
| 61 |
*--all*. |
| 62 |
|
| 63 |
By default task names that start with an underscore(*_*) are not listed. They |
| 64 |
are listed if the option *-p*/*--private* is used. |
| 65 |
|
| 66 |
Task's file-dependencies can be printed using the option *--deps*. |
| 67 |
|
| 68 |
status |
| 69 |
^^^^^^ |
| 70 |
|
| 71 |
If you would like to know if a task would actually be executed, |
| 72 |
the option *-s*/*--status* can be used to display the task's status . |
| 73 |
It is one of: |
| 74 |
|
| 75 |
- ``R``: run |
| 76 |
- ``U``: up-to-date |
| 77 |
- ``I``: ignored |
| 78 |
|
| 79 |
This is an alternative to *dry-run* or *preflight* feature provided by some tools. |
| 80 |
|
| 81 |
|
| 82 |
info |
| 83 |
---- |
| 84 |
|
| 85 |
You can check a task meta-data using the *info* command. |
| 86 |
This might be useful when have some complex code generating |
| 87 |
the task meta-data. |
| 88 |
|
| 89 |
.. code-block:: console |
| 90 |
|
| 91 |
$ doit info link |
| 92 |
|
| 93 |
link |
| 94 |
|
| 95 |
status : up-to-date |
| 96 |
|
| 97 |
file_dep: |
| 98 |
- command.o |
| 99 |
- kbd.o |
| 100 |
- main.o |
| 101 |
|
| 102 |
targets: |
| 103 |
- edit |
| 104 |
|
| 105 |
|
| 106 |
Note that if the task is **not** *up-to-date* the reason a task is not up-to-date. |
| 107 |
|
| 108 |
.. code-block:: console |
| 109 |
|
| 110 |
$ doit info link |
| 111 |
|
| 112 |
link |
| 113 |
|
| 114 |
status : run |
| 115 |
|
| 116 |
* The following file dependencies have changed: |
| 117 |
- main.o |
| 118 |
- kbd.o |
| 119 |
- command.o |
| 120 |
|
| 121 |
|
| 122 |
forget |
| 123 |
------- |
| 124 |
|
| 125 |
|
| 126 |
Suppose you change the compilation parameters in the compile action. Or you |
| 127 |
changed the code from a python-action. *doit* will think your task is up-to-date |
| 128 |
based on the dependencies but actually it is not! In this case you can use the |
| 129 |
*forget* command to make sure the given task will be executed again even with no |
| 130 |
changes in the dependencies. |
| 131 |
|
| 132 |
If you do not specify any task, the default tasks are "*forget*". |
| 133 |
|
| 134 |
.. code-block:: console |
| 135 |
|
| 136 |
$ doit forget |
| 137 |
|
| 138 |
.. note:: |
| 139 |
|
| 140 |
*doit* keeps track of which tasks are successful in the file ``.doit.db``. |
| 141 |
|
| 142 |
|
| 143 |
--disable-default |
| 144 |
^^^^^^^^^^^^^^^^^ |
| 145 |
|
| 146 |
If your default tasks are expensive, you can avoid accidentally forgetting |
| 147 |
all of your default tasks by setting ``forget_disable_default = True`` in ``doit.cfg``. |
| 148 |
|
| 149 |
You can explicitly forget default tasks with ``--enable-default``. |
| 150 |
|
| 151 |
--all |
| 152 |
^^^^^ |
| 153 |
|
| 154 |
Use ``doit forget --all`` to forget *all* tasks. |
| 155 |
|
| 156 |
|
| 157 |
clean |
| 158 |
------ |
| 159 |
|
| 160 |
A common scenario is a task that needs to "revert" its actions. A task may |
| 161 |
include a *clean* attribute. This attribute can be ``True`` to remove all of its |
| 162 |
target files. If there is a folder as a target it will be removed if the folder |
| 163 |
is empty, otherwise it will display a warning message. |
| 164 |
|
| 165 |
.. note:: |
| 166 |
|
| 167 |
The targets' removal order will be the reverse of their lexical ordering. |
| 168 |
This ensures that files in a directory are removed before the directory |
| 169 |
irrespective of their order in the ``targets`` array. |
| 170 |
|
| 171 |
The *clean* attribute can be a list of actions. An action could be a |
| 172 |
string with a shell command or a tuple with a python callable. |
| 173 |
|
| 174 |
If you want to clean the targets and add some custom clean actions, |
| 175 |
you can include the `doit.task.clean_targets` instead of passing `True`: |
| 176 |
|
| 177 |
.. literalinclude:: samples/clean_mix.py |
| 178 |
|
| 179 |
|
| 180 |
You can specify which task to *clean*. If no task is specified the clean operation of default tasks are executed. |
| 181 |
|
| 182 |
.. code-block:: console |
| 183 |
|
| 184 |
$ doit clean |
| 185 |
|
| 186 |
|
| 187 |
By default if a task contains task-dependencies those are not automatically |
| 188 |
cleaned too. You can enable this using the option *-c*/*--clean-dep*. |
| 189 |
If you are executing the default tasks this flag is automatically set. |
| 190 |
|
| 191 |
|
| 192 |
.. note:: |
| 193 |
|
| 194 |
By default only the default tasks' clean are executed, not from all tasks. |
| 195 |
You can clean all tasks using the *-a*/*--all* argument. |
| 196 |
|
| 197 |
If you like to also make doit forget previous execution of cleaned tasks, use option |
| 198 |
*--forget*. This can be made the default behavior by adding the corresponding ``cleanforget`` |
| 199 |
configuration switch: |
| 200 |
|
| 201 |
.. code-block:: python |
| 202 |
|
| 203 |
DOIT_CONFIG = { |
| 204 |
'cleanforget': True, |
| 205 |
} |
| 206 |
|
| 207 |
dry run |
| 208 |
^^^^^^^ |
| 209 |
|
| 210 |
If you want check which tasks the clean operation would affect you can use the option `-n/--dry-run`. |
| 211 |
|
| 212 |
When using a custom action on `dry-run`, the action is not executed at all |
| 213 |
**if** it does not include a `dryrun` parameter. |
| 214 |
|
| 215 |
If it includes a `dryrun` parameter the action will **always** be executed, |
| 216 |
and its implementation is responsible for handling the *dry-run* logic. |
| 217 |
|
| 218 |
.. literalinclude:: samples/custom_clean.py |
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
ignore |
| 224 |
------- |
| 225 |
|
| 226 |
It is possible to set a task to be ignored/skipped (that is, not executed). This |
| 227 |
is useful, for example, when you are performing checks in several files and you |
| 228 |
want to skip the check in some of them temporarily. |
| 229 |
|
| 230 |
.. literalinclude:: samples/subtasks.py |
| 231 |
|
| 232 |
|
| 233 |
.. code-block:: console |
| 234 |
|
| 235 |
$ doit |
| 236 |
. create_file:file0.txt |
| 237 |
. create_file:file1.txt |
| 238 |
. create_file:file2.txt |
| 239 |
$ doit ignore create_file:file1.txt |
| 240 |
ignoring create_file:file1.txt |
| 241 |
$ doit |
| 242 |
. create_file:file0.txt |
| 243 |
!! create_file:file1.txt |
| 244 |
. create_file:file2.txt |
| 245 |
|
| 246 |
Note the ``!!``, it means that task was ignored. To reverse the `ignore` use |
| 247 |
`forget` sub-command. |
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
.. _cmd-auto: |
| 252 |
|
| 253 |
auto (watch) |
| 254 |
------------- |
| 255 |
|
| 256 |
.. note:: |
| 257 |
|
| 258 |
Supported on Linux and Mac only. |
| 259 |
|
| 260 |
`auto` is provided through the package `doit-auto1 <https://github.com/pydoit/doit-auto1>`_ plugin. |
| 261 |
To install it:: |
| 262 |
|
| 263 |
$ pip install doit-auto1 |
| 264 |
|
| 265 |
`auto` sub-command is an alternative way of executing your tasks. It is a long |
| 266 |
running process that only terminates when it is interrupted `Ctrl-C`. |
| 267 |
When started it will execute the given tasks. After that it will watch the |
| 268 |
file system for modifications in the file-dependencies. |
| 269 |
When a file is modified the tasks are re-executed. |
| 270 |
|
| 271 |
.. code-block:: console |
| 272 |
|
| 273 |
$ doit auto |
| 274 |
|
| 275 |
|
| 276 |
.. note:: |
| 277 |
|
| 278 |
The `dodo` file is actually re-loaded/executed in a separate process |
| 279 |
every time tasks need to be re-executed. |
| 280 |
|
| 281 |
|
| 282 |
callbacks |
| 283 |
^^^^^^^^^ |
| 284 |
|
| 285 |
It is possible to specify shell commands to executed after every cycle |
| 286 |
of task execution. |
| 287 |
This can used to display desktop notifications, so you do not need to keep |
| 288 |
an eye in the terminal to notice when tasks succeed or failed. |
| 289 |
|
| 290 |
Example of sound and desktop notification on Ubuntu. |
| 291 |
|
| 292 |
Contents of a `pyproject.toml` file: |
| 293 |
|
| 294 |
.. code-block:: toml |
| 295 |
|
| 296 |
[tool.doit.commands.auto] |
| 297 |
success_callback = """ |
| 298 |
notify-send -u low -i /usr/share/icons/gnome/16x16/emotes/face-smile.png "doit: success"; aplay -q /usr/share/sounds/purple/send.wav |
| 299 |
""" |
| 300 |
failure_callback = """ |
| 301 |
notify-send -u normal -i /usr/share/icons/gnome/16x16/status/error.png "doit: fail"; aplay -q /usr/share/sounds/purple/alert.wav |
| 302 |
""" |
| 303 |
|
| 304 |
|
| 305 |
Contents of a `doit.cfg` file: |
| 306 |
|
| 307 |
.. code-block:: ini |
| 308 |
|
| 309 |
[auto] |
| 310 |
success_callback = notify-send -u low -i /usr/share/icons/gnome/16x16/emotes/face-smile.png "doit: success"; aplay -q /usr/share/sounds/purple/send.wav |
| 311 |
failure_callback = notify-send -u normal -i /usr/share/icons/gnome/16x16/status/error.png "doit: fail"; aplay -q /usr/share/sounds/purple/alert.wav |
| 312 |
|
| 313 |
|
| 314 |
|
| 315 |
``watch`` parameter |
| 316 |
^^^^^^^^^^^^^^^^^^^^^ |
| 317 |
|
| 318 |
Apart from ``file_dep`` you can use the parameter ``watch`` to pass extra |
| 319 |
paths to be watched for (including folders). |
| 320 |
If paths are folders their sub-folders will not be watched unless these |
| 321 |
sub-folders are also part of the given extra paths. |
| 322 |
The ``watch`` parameter can also be specified for a group of "sub-tasks". |
| 323 |
|
| 324 |
.. literalinclude:: samples/empty_subtasks.py |
| 325 |
|
| 326 |
|
| 327 |
.. _tabcompletion: |
| 328 |
|
| 329 |
tabcompletion |
| 330 |
---------------- |
| 331 |
|
| 332 |
This command creates a completion for bash or zsh. |
| 333 |
The generated script is written on stdout. |
| 334 |
|
| 335 |
bash |
| 336 |
^^^^^^ |
| 337 |
|
| 338 |
To use a completion script you need to `source` it first. |
| 339 |
|
| 340 |
.. code-block:: console |
| 341 |
|
| 342 |
$ doit tabcompletion > bash_completion_doit |
| 343 |
$ source bash_completion_doit |
| 344 |
|
| 345 |
|
| 346 |
zsh |
| 347 |
^^^^^ |
| 348 |
|
| 349 |
zsh completion scripts should be placed in a folder in the "autoload" path. |
| 350 |
|
| 351 |
.. code-block:: sh |
| 352 |
|
| 353 |
# add folder with completion scripts |
| 354 |
fpath=(~/.zsh/tabcompletion $fpath) |
| 355 |
|
| 356 |
# Use modern completion system |
| 357 |
autoload -Uz compinit |
| 358 |
compinit |
| 359 |
|
| 360 |
|
| 361 |
.. code-block:: console |
| 362 |
|
| 363 |
$ doit tabcompletion --shell zsh > _doit |
| 364 |
$ cp _doit ~/.zsh/tabcompletion/_doit |
| 365 |
|
| 366 |
|
| 367 |
hard-coding tasks |
| 368 |
^^^^^^^^^^^^^^^^^^^^ |
| 369 |
|
| 370 |
If you are creating an application based on `doit` |
| 371 |
or if you tasks take a long time to load you may create |
| 372 |
a completion script that includes the list of tasks |
| 373 |
from your dodo.py. |
| 374 |
|
| 375 |
.. code-block:: console |
| 376 |
|
| 377 |
$ my_app tabcompletion --hardcode-tasks > _my_app |
| 378 |
|
| 379 |
|
| 380 |
|
| 381 |
dumpdb |
| 382 |
-------- |
| 383 |
|
| 384 |
`doit` saves internal data in a file (`.doit.db` by default). |
| 385 |
It uses a binary format (whatever python's dbm is using in your system). |
| 386 |
This command will simply dump its content in readable text format in the output. |
| 387 |
|
| 388 |
.. code-block:: console |
| 389 |
|
| 390 |
$ doit dumpdb |
| 391 |
|
| 392 |
|
| 393 |
|
| 394 |
strace |
| 395 |
-------- |
| 396 |
|
| 397 |
This command uses `strace <https://en.wikipedia.org/wiki/Strace>`_ |
| 398 |
utility to help you verify which files are being used by a given task. |
| 399 |
|
| 400 |
The output is a list of files prefixed with `R` for open in read mode |
| 401 |
or `W` for open in write mode. |
| 402 |
The files are listed in chronological order. |
| 403 |
|
| 404 |
This is a debugging feature with many limitations. |
| 405 |
* can strace only one task at a time |
| 406 |
* can only strace CmdAction |
| 407 |
* the process being traced itself might have some kind of cache, |
| 408 |
that means it might not write a target file if it exist |
| 409 |
* does not handle chdir |
| 410 |
|
| 411 |
So this is NOT 100% reliable, use with care! |
| 412 |
|
| 413 |
.. code-block:: console |
| 414 |
|
| 415 |
$ doit strace <task-name> |
| 416 |
|
| 417 |
|
| 418 |
|
| 419 |
reset-dep |
| 420 |
--------- |
| 421 |
|
| 422 |
This command allows to recompute the information on file dependencies |
| 423 |
(timestamp, md5sum, ... depending on the ``check_file_uptodate`` setting), and |
| 424 |
save this in the database, without executing the actions. |
| 425 |
|
| 426 |
The command run on all tasks by default, but it is possible to specify a list |
| 427 |
of tasks to work on. |
| 428 |
|
| 429 |
This is useful when the targets of your tasks already exist, and you want doit |
| 430 |
to consider your tasks as up-to-date. One use-case for this command is when you |
| 431 |
change the ``check_file_uptodate`` setting, which cause doit to consider all |
| 432 |
your tasks as not up-to-date. It is also useful if you start using doit while |
| 433 |
some of your data as already been computed, or when you add a file dependency |
| 434 |
to a task that has already run. |
| 435 |
|
| 436 |
.. code-block:: console |
| 437 |
|
| 438 |
$ doit reset-dep |
| 439 |
|
| 440 |
.. warning:: |
| 441 |
|
| 442 |
`reset-dep` will **NOT** recalculate task `values` and `result`. |
| 443 |
This might not be the correct behavior for your tasks! |
| 444 |
|
| 445 |
It is safe to use `reset-dep` if your tasks rely only on files to control its |
| 446 |
up-to-date status. So only use this command if you are sure it is OK for your |
| 447 |
tasks. |
| 448 |
|
| 449 |
If the DB already has any saved `values` or `result` they will be preserved |
| 450 |
otherwise they will not be set at all. |