- Notifications
You must be signed in to change notification settings - Fork0
lamyj/spire
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
Spire is a thin wrapper arounddoit. It eases the declaration of tasks through:
- Class-based task declarations
- Built-in factories for repetitive tasks
- Optional pruning of the task graph when some dependencies are missing
Moreover, tasks will be rerun whenever their actions are modified.
Spire tasks can be classes: this syntax facilitates the reusability of dependencies and targets in the list of actions.
importspireclassBuildHouse(spire.Task):file_dep= ["brick","mortar"]targets= ["house","dog_house"]actions= [["build"]+file_dep+targets]
This task file can then be run with the usualdoit
command:
$doit run -f build_house.py -d /home/somebody/vacant_lot. BuildHouse
For simple tasks (single target or single action), it is not mandatory to use lists. In this case, the singular form of the member name must be used (i.e.targets becomestarget andactions becomesaction).
importspireclassBuildShed(spire.Task):file_dep="wood"target="shed"action= ["build",file_dep,target]
Spire tasks are cleanable by default: using the previous examples, callingdoit clean -f ... -d ...
will remove the targets.
For repetitive tasks, Spire provides theTaskFactory
class. Classes derived fromTaskFactory
need to set the following members for each object:
- The task name, through the constructor of
TaskFactory
file_dep
,targets
andactions
importspireclassBuildHouse(spire.TaskFactory):def__init__(self,material):spire.TaskFactory.__init__(self,"Build{}House".format(material))self.file_dep= [material]self.targets= ["{}_house".format(material)]self.actions= [["build",material]]houses= [BuildHouse(material)formaterialin ["Straw","Sticks","Bricks"]]
Tasks with missing dependencies may be skipped instead of being executed and failing. For this, missing dependencies must be specified asNone
entries infile_dep
, and the functionspire.prune()
must be called. The task graph will be pruned starting at the current task, ensuring that no error will occur on account of these missing targets.
In the following example, if eitherbrick
ormortar
is missing, neitherBuildHouse
norBuildDogHouse
will be executed:
BuildHouse
will be skipped sincefile_dep
contains entries which areNone
andspire.prune()
was calledBuildDogHouse
will be skipped since one of its parent has been skipped.
On the other hand, ifbrick
andmortar
are present butdoggie_basket
is missing,BuildHouse
will be successfully executed butBuildDogHouse
will fail as none of itsfile_dep
equalNone
.
importosimportspireclassBuildHouse(spire.Task):file_dep= [xifos.path.isfile(x)elseNoneforxin ["brick","mortar"]]target="house"action= ["build"]+file_dep+ [target]classBuildDogHouse(spire.Task):file_dep= [BuildHouse.target,"doggie_basket"]target="dog_house"action= ["build"]+file_dep+ [target]spire.prune()
A graphical representation of the task graph, in theGraphviz format, can be generated by calling thespire
module:
$ python3 -m spire graph tasks.py tasks.dot
A simplified representation, omitting the targets and dependencies nodes, can be generated py passing the option--tasks-only
. Any other option will be passed directly todoit, e.g. to specify command-line variables.
About
A simple pipeline engine