Sysyphus is a lightweight framework to automate stuff, written in Python. It's useful to write build and automation scripts in the Python programming language, using a very simple API. It's similar in spirit to build tools like ant, but uses pure Python syntax to define tasks.
Sysyphus-0.3.tar.gz (8 KB, 10/03/2005)
"""This example build script exhibits almost all of Sysyphus' features."""
import os, unittest
from Sysyphus import TaskList, depends
class ExampleBuild(TaskList):
python = "python2.4"
def taskTest(self):
"""Runs unit tests."""
import test_example
runner = unittest.TextTestRunner(verbosity=1)
runner.run(unittest.TestLoader().loadTestsFromModule(test_example))
def taskSdist(self):
"""Creates a source distribution."""
# If Python's exit code is anything other than 0 (ie, there was some
# kind of error), abort the task execution chain by returning False
return os.system("%s setup.py sdist" % self.python) == 0
@depends("test", "sdist")
def taskDeploy(self):
"""Deploys the current version."""
os.system("tar xvzf dist/example.tar.gz --directory=dist")
os.system("%s dist/example/setup.py install" % self.python)
if __name__ == "__main__":
ExampleBuild().commandLineTasks()
Tasks are methods with the prefix task (or task_ if you're not into CamelCase), defined on a subclass of the Sysyphus.TaskList class. What follows after the prefix is the name of the task.
Arbitrary Python code can be used to define actions in a task. There are no predefined tasks; it's lightweight, we told you.
Call the commandLineTasks method of a task list to execute tasks specified by name on the command line. Assuming the above script is saved in the file build.py, the test task can be executed like this:
python build.py test
To execute several tasks simply pass more task names on the command line, e.g.:
python build.py test deploy
Note that in this particular case Sysyphus will detect that deploy depends on test and will thus execute the test task only once.
Dependencies can be specified using the @depends decorator syntax as shown in the deploy task of the example script.
@-Decorators are language feature introduced in Python 2.4. If you're using a Python version prior to 2.4 (Sysyphus will work with version 2.2 or higher) you'll have to use the less convenient old decorator syntax, e.g.:
def taskFoo(self):
pass
taskFoo = depends("bar")(taskFoo)
Tasks may optionally return a value. If this value evaluates to False (but is not None), the task is considered aborted. This means that any further tasks scheduled for execution will be discarded.
For example, the deploy of the example depends on test and sdist. If it is executed, these two dependencies are executed first. If the os.system call in sdist fails for some reason and returns an exit code other than 0, the whole execution chain is aborted and the deploy task will not actually be executed.
Variables defined on the class level are considered properties (e.g. the python class variable in the example script). They can be adapted for specific runs of the script. For example, to build a source distribution using Python 2.2 you would use:
python build.py --python=python2.2 sdist
This sets the python class variable to the string "python2.2" for this execution.
Sysyphus is Copyright © 2003-2005, Nik Haldimann. It comes with a BSD-style license: You may use and modify it freely as well as redistribute it under certain conditions. See the LICENSE.txt file in the distribution for details.