Debian Codegraph @

doc/globals.rst

raw
1 .. meta::
2 :description: Accessing doit internal database
3 :keywords: python, doit, documentation, guide, database, status
4
5 .. title:: Accessing doit internal database - pydoit guide
6
7
8 ==================================
9 Globals - accessing doit internals
10 ==================================
11
12 During the life-cycle of a command invocation,
13 some properties of `doit` are stored in global singletons,
14 provided by the ``doit.Globals`` class.
15
16 .. autoclass:: doit.globals.Globals
17 :members:
18
19 dep_manager
20 -----------
21
22 The doit dependency manager holds the persistent state of `doit`.
23 This includes relations of tasks among each other or results,
24 returned from their latest runs. It basically consists of all the
25 information stored in `doit`'s database file.
26
27 The ``dep_manager`` attribute is initialized right before tasks are loaded,
28 which means it allows to be accessed during *all* task evaluation phases,
29 in particular during:
30
31 * Task creation, i.e. from the body of any ``task_*`` function.
32 * Task execution, i.e. from the code executed by one of the task's actions.
33 * Task cleanup, i.e. from the the code executed by one of the tasks's clean activities.
34
35 The `Dependency` class has members to access persistent doit data via its API:
36
37 .. autoclass:: doit.dependency.Dependency
38 :members: get_values, get_value, get_result
39
40 The class internally interacts with a data base backend
41 which may be accessed via the `backend` attribute.
42 An experienced user may also *modify* persistently stored *doit* data through that attribute.
43 As an example of a backend API,
44 look at the common methods exposed by the default `DbmDB` backend implementation:
45
46 .. class:: doit.dependency.DbmDB
47
48 A simple Key-Value database interface
49
50 .. automethod:: doit.dependency.DbmDB.get
51 .. automethod:: doit.dependency.DbmDB.set
52 .. automethod:: doit.dependency.DbmDB.remove
53
54 There are other backends available in *doit*,
55 see the documentation on :ref:`db_backends` on how to select between them.
56
57
58 ``dep_manager`` example
59 +++++++++++++++++++++++
60
61 An example of using the exposed dependency manager is a task,
62 where at creation time the *target* of the task action is not yet known,
63 because it is determined during execution.
64 Then it would be possible to store that target in the dependency manager
65 by returning it from the action.
66 A `clean` action is subsequently able to query `dep_manager` for that result
67 and perform the cleanup action:
68
69
70 .. literalinclude:: samples/global_dep_manager.py