Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Run software pipelines using doit

Project description


Spire is a thin wrapper around doit. 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.

Task declaration

Spire tasks can be classes: this syntax facilitates the reusability of dependencies and targets in the list of actions.

import spire

class BuildHouse(spire.Task):
    file_dep = ["brick", "mortar"]
    targets = ["house", "dog_house"]
    actions = [["build"]+file_dep+targets]

This task file can then be run with the usual doit command:

$ doit run -f -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 becomes target and actions becomes action).

import spire

class BuildShed(spire.Task):
    file_dep = "wood"
    target = "shed"
    action = ["build", file_dep, target]

Spire tasks are cleanable by default: using the previous examples, calling doit clean -f ... -d ... will remove the targets.

Repetitive tasks

For repetitive tasks, Spire provides the TaskFactory class. Classes derived from TaskFactory need to set the following members for each object:

  • The task name, through the constructor of TaskFactory
  • file_dep, targets and actions
import spire

class BuildHouse(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) for material in ["Straw", "Sticks", "Bricks"]]

Pruning the task graph

Tasks with missing dependencies may be skipped instead of being executed and failing. For this, missing dependencies must be specified as None entries in file_dep, and the function spire.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 either brick or mortar is missing, neither BuildHouse nor BuildDogHouse will be executed:

  • BuildHouse will be skipped since file_dep contains entries which are None and spire.prune() was called
  • BuildDogHouse will be skipped since one of its parent has been skipped.

On the other hand, if brick and mortar are present but doggie_basket is missing, BuildHouse will be successfully executed but BuildDogHouse will fail as none of its file_dep equal None.

import os
import spire

class BuildHouse(spire.Task):
    file_dep = [x if os.path.isfile(x) else None for x in ["brick", "mortar"]]
    target = "house"
    action = ["build"] + file_dep  + [target]

class BuildDogHouse(spire.Task):
    file_dep = [, "doggie_basket"]
    target = "dog_house"
    action = ["build"] + file_dep  + [target]


Graphical representation of the task graph

A graphical representation of the task graph, in the Graphviz format, can be generated by calling the spire module:

$ python3 -m spire graph

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 to doit, e.g. to specify command-line variables.

Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for spire-pipeline, version 1.0.2
Filename, size File type Python version Upload date Hashes
Filename, size spire_pipeline-1.0.2-py3-none-any.whl (19.1 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size spire-pipeline-1.0.2.tar.gz (15.8 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page