| 1 |
.. meta:: |
| 2 |
:description: Help snippets for tasks and integrations |
| 3 |
:keywords: python, doit, documentation, guide, ipython, interactive |
| 4 |
|
| 5 |
.. title:: help snippets for tasks and integrations - pydoit guide |
| 6 |
|
| 7 |
|
| 8 |
==================== |
| 9 |
Tools & Integrations |
| 10 |
==================== |
| 11 |
|
| 12 |
`doit.tools` includes some commonly used code. These are not used by the `doit` |
| 13 |
core, you can see it as a "standard library". |
| 14 |
The functions/class used with `uptodate` were already introduced in the previous |
| 15 |
section. |
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
create_folder (action) |
| 20 |
------------------------- |
| 21 |
|
| 22 |
Creates a folder if it does not exist yet. Uses `os.makedirs() <http://docs.python.org/2/library/os#os.makedirs>_`. |
| 23 |
|
| 24 |
.. literalinclude:: samples/folder.py |
| 25 |
|
| 26 |
|
| 27 |
title_with_actions (title) |
| 28 |
---------------------------- |
| 29 |
|
| 30 |
Return task name task actions from a task. This function can be used as 'title' attribute of a task dictionary to provide more detailed information of the action being executed. |
| 31 |
|
| 32 |
.. literalinclude:: samples/titlewithactions.py |
| 33 |
|
| 34 |
|
| 35 |
.. _tools.LongRunning: |
| 36 |
|
| 37 |
LongRunning (action) |
| 38 |
----------------------------- |
| 39 |
|
| 40 |
.. autoclass:: doit.tools.LongRunning |
| 41 |
|
| 42 |
|
| 43 |
This is useful for executing long running process like a web-server. |
| 44 |
|
| 45 |
.. literalinclude:: samples/longrunning.py |
| 46 |
|
| 47 |
|
| 48 |
Interactive (action) |
| 49 |
---------------------------------- |
| 50 |
|
| 51 |
.. autoclass:: doit.tools.Interactive |
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
PythonInteractiveAction (action) |
| 56 |
---------------------------------- |
| 57 |
|
| 58 |
.. autoclass:: doit.tools.PythonInteractiveAction |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
set_trace |
| 63 |
----------- |
| 64 |
|
| 65 |
`doit` by default redirects stdout and stderr. Because of this when you try to |
| 66 |
use the python debugger with ``pdb.set_trace``, it does not work properly. |
| 67 |
To make sure you get a proper PDB shell you should use doit.tools.set_trace |
| 68 |
instead of ``pdb.set_trace``. |
| 69 |
|
| 70 |
.. literalinclude:: samples/settrace.py |
| 71 |
|
| 72 |
|
| 73 |
.. _tools.IPython: |
| 74 |
|
| 75 |
IPython integration |
| 76 |
---------------------- |
| 77 |
|
| 78 |
A handy possibility for interactive experimentation is to define tasks from |
| 79 |
within *ipython* sessions and use the ``%doit`` `magic function |
| 80 |
<http://ipython.org/ipython-doc/dev/interactive/tutorial.html#magic-functions>`_ |
| 81 |
to discover and execute them. |
| 82 |
|
| 83 |
|
| 84 |
First you need to register the new magic function into ipython shell. |
| 85 |
|
| 86 |
.. code-block:: pycon |
| 87 |
|
| 88 |
>>> %load_ext doit.tools |
| 89 |
|
| 90 |
|
| 91 |
.. Tip:: |
| 92 |
To permanently add this magic-function to your IPython include it on your |
| 93 |
`profile <http://ipython.org/ipython-doc/3/config/intro.html?highlight=profile#profiles>`_, |
| 94 |
create a new script inside your startup-profile |
| 95 |
(i.e. :file:`~/.ipython/profile_default/startup/doit_magic.ipy`) |
| 96 |
with the following content:: |
| 97 |
|
| 98 |
from doit import load_ipython_extension |
| 99 |
load_ipython_extension() |
| 100 |
|
| 101 |
Then you can define your `task_creator` functions and invoke them with `%doit` |
| 102 |
magic-function, instead of invoking the cmd-line script with a :file:`dodo.py` |
| 103 |
file. |
| 104 |
|
| 105 |
|
| 106 |
Examples: |
| 107 |
|
| 108 |
.. code-block:: pycon |
| 109 |
|
| 110 |
>>> %doit --help ## Show help for options and arguments. |
| 111 |
|
| 112 |
>>> def task_foo(): |
| 113 |
return {'actions': ["echo hi IPython"], |
| 114 |
'verbosity': 2} |
| 115 |
|
| 116 |
>>> %doit list ## List any tasks discovered. |
| 117 |
foo |
| 118 |
|
| 119 |
>>> %doit ## Run any tasks. |
| 120 |
. foo |
| 121 |
hi IPython |