| 1 |
.. meta:: |
| 2 |
:description: pydoit is a generic tool based on build-tool concepts. Flexible and scalable. |
| 3 |
:keywords: python, doit, CLI, linux, windows, task-runner, build-tool, pipeline, workflow, incremental build, data pipeline |
| 4 |
|
| 5 |
.. title:: pydoit use cases - from CLI task-runner to complex pipelines |
| 6 |
|
| 7 |
========= |
| 8 |
Use Cases |
| 9 |
========= |
| 10 |
|
| 11 |
Here are some use cases, where `doit` can help you with automation of your tasks. |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
Simplify cumbersome command line calls |
| 16 |
====================================== |
| 17 |
|
| 18 |
Do you have to repeatedly call complex command like this? |
| 19 |
|
| 20 |
.. code-block:: console |
| 21 |
|
| 22 |
$ aws s3 sync _built/html s3://buck/et --exclude "*" --include "*.html" |
| 23 |
|
| 24 |
|
| 25 |
Wrap it into `dodo.py` file: |
| 26 |
|
| 27 |
.. code-block:: python |
| 28 |
|
| 29 |
def task_publish(): |
| 30 |
"""Publish to AWS S3""" |
| 31 |
return { |
| 32 |
"actions": [ |
| 33 |
'aws s3 sync _built/html s3://buck/et --exclude "*" --include "*.html"' |
| 34 |
] |
| 35 |
} |
| 36 |
|
| 37 |
and next time just: |
| 38 |
|
| 39 |
.. code-block:: console |
| 40 |
|
| 41 |
$ doit publish |
| 42 |
|
| 43 |
It is easy to include multiple actions into one task or use multiple tasks. |
| 44 |
|
| 45 |
|
| 46 |
Automate typical project related actions |
| 47 |
======================================== |
| 48 |
|
| 49 |
Do you have to lint your code, run test suite, evaluate coverage, |
| 50 |
generate documentation incl. spelling? |
| 51 |
|
| 52 |
Create the `dodo.py`, which defines tasks you have to do and next time: |
| 53 |
|
| 54 |
.. code-block:: console |
| 55 |
|
| 56 |
$ doit list |
| 57 |
coverage show coverage for all modules including tests |
| 58 |
coverage_module show coverage for individual modules |
| 59 |
coverage_src show coverage for all modules (exclude tests) |
| 60 |
package create/upload package to pypi |
| 61 |
pyflakes |
| 62 |
pypi create/upload package to pypi |
| 63 |
spell spell checker for doc files |
| 64 |
sphinx build sphinx docs |
| 65 |
tutorial_check check tutorial sample are at least runnable without error |
| 66 |
ut run unit-tests |
| 67 |
website dodo file create website html files |
| 68 |
website_update update website on SITE_PATH |
| 69 |
|
| 70 |
and then decide which task to run: |
| 71 |
|
| 72 |
.. code-block:: console |
| 73 |
|
| 74 |
$ doit spell |
| 75 |
|
| 76 |
Share unified way of doing things |
| 77 |
================================= |
| 78 |
|
| 79 |
Do you expect your colleagues perform the same steps before committing |
| 80 |
changes to repository? What to do with the complains the steps are too complex? |
| 81 |
|
| 82 |
Provide them with the `dodo.py` file doing the things. What goes easy, |
| 83 |
is more likely to be used. |
| 84 |
|
| 85 |
`dodo.py` will become easy to use prescription of best practices. |
| 86 |
|
| 87 |
Optimize processing time by skipping tasks already done |
| 88 |
======================================================= |
| 89 |
|
| 90 |
You dump your database and convert the data to CSV. It takes minutes, |
| 91 |
but often the input is the same as before. Why to do things already |
| 92 |
done and wait? |
| 93 |
|
| 94 |
Wrap the conversion into `doit` task and `doit` will automatically |
| 95 |
detect, the input and output are already in sync and complete in |
| 96 |
fraction of a second, when possible. |
| 97 |
|
| 98 |
Manage complex set of depending tasks |
| 99 |
===================================== |
| 100 |
|
| 101 |
The system you code shall do many small actions, which are interdependent. |
| 102 |
|
| 103 |
Split it into small tasks, define (file) dependencies and let `doit` |
| 104 |
do the planning of what shall be processed first and what next. |
| 105 |
|
| 106 |
Your solution will be clean and modular. |
| 107 |
|
| 108 |
Speed up by parallel task execution |
| 109 |
=================================== |
| 110 |
You already have bunch of tasks defined, results are correct, it only takes so |
| 111 |
much time. But wait, you have multi-core machine! |
| 112 |
|
| 113 |
Just ask for parallel processing: |
| 114 |
|
| 115 |
.. code-block:: console |
| 116 |
|
| 117 |
$ doit -n 4 |
| 118 |
|
| 119 |
and `doit` will take care of planning and make all your CPU cores hot. |
| 120 |
|
| 121 |
No need to rewrite your processing from scratch, properly declared tasks is all |
| 122 |
what you have to provide. |
| 123 |
|
| 124 |
Extend your project by doit features |
| 125 |
==================================== |
| 126 |
Your own python project would need features of `doit`, but you cannot ask your users to call `doit` on command line? |
| 127 |
|
| 128 |
Simply integrate `doit` functionality into your own command line tool and nobody will notice where it comes from. |
| 129 |
|
| 130 |
Create cross-platform tool for processing your stuff |
| 131 |
===================================================== |
| 132 |
Do you have team members working on MS Windows and others on Linux? |
| 133 |
|
| 134 |
Scripts are great, but all those small shell differences prevent |
| 135 |
single reusable solution. |
| 136 |
|
| 137 |
With `dodo.py` and python you are more likely to write the processing |
| 138 |
in cross-platform way. Use `pathlib.Path` and `shutils` magic to |
| 139 |
create directories, move files around, copy them, etc. |