Hatch is a build system similar to Apache Ant. It is written in python and has an easily extendable task system. Hatch is modeled after Ant but uses a different syntax for build files. Although certain aspects of Hatch are oriented toward python development, it aims to be a more general and lightweight tool.
Note
Hatch is currently alpha level due to not having a wide testing audience as of yet. Also, none of it has been tested on Windows so far and certainly things are broken there.
Hatch uses XML build files, much like Apache Ant. Each file contains one project and at least one target. Each target contains one or more tasks.
simple build file:
<?xml version="1.0"?> <!-- project wrapper --> <project name="sample" basedir="." default="run"> <!-- target wrapper --> <target name="run" depends="" description="run ls" > <!-- task --> <execute cmd="ls -l" verbose="true" /> </target> </project>
Attribute | Required | Description |
---|---|---|
name | no | the name of the project |
basedir | no | the base directory |
default | no | the default target |
Targets can depend on other targets. Note that running a target simply flags that target as having run. It does not necessarily mean it ran successfully.
Attribute | Required | Description |
---|---|---|
name | yes | the target name |
depends | no | comma separated list of other target names that must be run before this target is run |
if | no | runs target if property is set |
unless | no | runs target if property is not set |
description | no | short description of what this target does, for humans. |
Type:
hatch --help
You can add tasks easily on a project specific basis.
For example, we want a tag called dumpdb that dumps mysql data from our project database.
run:
hatch --mktask dumpdb
This will create a directory called hatch_tasks underneath your build directory, if it's not already there, containing a task template file called dumpdb.py.
Now edit the file hatch_tests/dumpdb.py and change it to read as follows:
"""dumpdb - use mysqldump to dump our database <dumpdb db="" table="" file="" /> """ import os import hatch.tasks.basetask # ==================================================================== class dumpdbTask( hatch.tasks.basetask.BaseTask ): # ---------------------------------------------------------------- def run( self ): db = None table = None file = None if self._node.hasAttribute('db'): db = self.expand(self._node.getAttribute('db')) if self._node.hasAttribute('table'): table = self.expand(self._node.getAttribute('table')) if self._node.hasAttribute('file'): file = self.expand(self._node.getAttribute('file')) if file is None: self.fatal( 'Must supply a file tag' ) cmd = 'mysqldump' if db is not None: cmd += ' ' + db if table is not None: cmd += ' ' + table cmd += ' > ' + file (status,output) = self.system( cmd ) if self._verbose: print output
Now you can use it in a target in your build file like:
<dumpdb db='proj_db' table='some_table' file='some_table.sql' />
You can also add your task file to the site by copying it to $PYTHON_SITE_PATH/hatch/tasks.
If your task generic enough and you think it would help others, please consider submitting it to the project patch tracker.