Archive for November, 2009

PAnt Documentation Has Been Updated

Posted on 11/30/2009 , Alexander Ananiev, No Comments ( Add )

We've just updated PAnt documentation to reflect changes implemented in PAnt 2.0. There are two significat changes:

You can follow this guide to get started with PAnt.

How to Get Started with PAnt

Posted on 11/17/2009 , Alexander Ananiev, No Comments ( Add )

We just added How to Get Started with PAnt page explaining PAnt setup process. The rest of PAnt documentation should get updated later this week.

Creating Ant Targets in Python with PAnt 2.0

Posted on 11/10/2009 , Alexander Ananiev, No Comments ( Add )

We've just released a new version of PAnt, a tool for developing build scripts in python. The key new feature of PAnt 2.0 is the ability to create Ant targets directly from python. This allows for completely getting rid of Ant XML files and for developing build scripts entirely in Python.

PAnt makes creating Ant targets in python truly trivial:

@target
def ptarget1():
    """Python project ptarget1"""
    ant.echo("echo ptarget1")

As you can see, we use python decorators (decorators are similar to Java annotations) to denote functions that will be invoked when we run Ant targets. "target" decorator uses function name and doc string to set target's name and description respectively. Other target's attributes, such as "if", "unless" and "depends" are supplied using keyword arguments of the decorator. The target name could be manually provided that way too:

@target(name="p.target2", unless="prop.name", depends=ptarget1)
def p_target2():
    """Python project ptarget2"""
    ant.echo("echo ptarget2")


Note how we can simply point to another function in "depends" instead of providing a string name (although the string name is supported as well). Using python functions instead of strings allows for being able to rely on IDE (such as PyDev) for auto-completion and name verification.

PAnt comes with "pimport" task that creates Ant targets from any python module that uses 'target' decorators (you can define your targets in multiple modules as well). The task works much the same way with Ant "import" task, all you need to do is to invoke it somewhere in your Ant build file ("pimport" has to reside outside of any target).

With PAnt you can freely mix and match targets defined in XML and in python. You can also override XML targets in python and vice-versa. However, there is really no reason to be stuck with XML when you can use full power of python. So we recommend creating a small "starter" "build.xml" with a single "pimport" call and have all your target definitions done in python.

PAnt also provides a programmatic way of creating Ant targets using "antarget" function:

    antarget(ptarget2, if_="prop.name", depends=ptarget1)


The signature of "antarget" is similar to the "target" decorator; the main difference is that a function has to be provided as an argument. Note that using decorators requires Jython 2.5 whereas "antarget" can be used with Jython 2.2.

You can download the latest version of PAnt from PAnt project page. The documentation is currently out of date; we will be updating it soon. PAnt distribution comes with detailed examples.

Most Popular Posts

Recent Tweets

Recent Posts

Blog Categories

Blog Archives