Package: pub
pubis a tool to help you automate those tasks you don’t want to do
manually. It attempts to provide the cleanest, sanest interface for your
building, cleaning, and deploying needs.Pub code is simply python code, allowing you to leverage the skills and
tools you’re already familiar with.Simply installpub, save apub.pyfile in a dir, and start
coding.Here’s an example pub.py with two tasks, one to build a project and one
to deploy it to a server:from pub import task
from pub.shortcuts import mkdir, cp, rsync

@task
def build():
    mkdir("build")
    cp("src/binary", "build")

@task("build")
def deploy():
    rsync("build", "user@server:~")The pub.shortcuts module gives us handy shortcuts to access command-line
functionality.Thedeploytask depends on thebuildtask, so callingpub deploywill first run the build task, then deploy.Installationpip install pubTasksThetaskdecorator in the pub module will be your code’s main
interface to pub.You may create a task with no arguments:from pub import task

@task
def zomg():
    print "omgbbq"If you runpub zomgon a pub.py file containing this function, you
will see “omgbbq” printed out.You may also create a task with arguments. Each argument should be the
name of another function. The functions in the argument list will all be
executed before your task.For example:from pub import task

@task
def foo():
    print "foo"

@task("foo")
def bar():
    print "bar"

@task("foo", "bar")
def baz():
    print "baz"If you runpub foo, you will see “foo”.If you runpub bar, you will see “foo” followed by “bar”.If you runpub baz, you will see “foo” followed by “bar” followed by
“baz”.Dependencies will be resolved left-to-right, meaning that there’s an
implied dependency of each item in a dependency list on its left-hand
neighbor. Be careful that you don’t create a circular dependency like
so:from pub import task

@task
def foo():
    print "foo"

@task("foo")
def bar():
    print "bar"

@task("bar", "foo")
def baz():
    print "baz"In this case,bardepends onfooby the definition ofbar,
butfoodepends onbarby the definition ofbaz. Pub will be
confused about this situation, and resolve it by quitting out with an
error.There are two legal keywords you can use with the task decorator:privateanddefault.privatejust means thatpub-lwon’t list your task; if you have apub.pyfile like:from pub import task

@task(private=True)
def private_func(): passand you runpub-l, which normally lists all tasks,private_funcwill not be listed.defaultmarks the task as a default action. If you have apub.pylike:from pub import task

@task(default=True)
def do_something(): print "got here"and runpubwith no arguments, you should see “got here” printed.You may mark any number of tasks asdefault; they will all be run ifpubis invoked without arguments. While their dependency information
will never be ignored, there is no defined order in which they will be
run.Tasks are documented simply by giving them docstrings. Given thispub.py:from pub import task

@task
def gotit():
    """You've got it!"""
    pass

@task
def noyou():
    """I thought you had it."""
    passWe can see how they are displayed by pub:$ pub -l
gotit: You've got it!
noyou: I thought you had it.ShortcutsThepub.shortcutsmodule builds on @kennethreitz’s fineenvoymodule to provide a
convenient command-line interface for pub.You can see all the commands that are availablein the
source,
or you can make your own:from pub.shortcuts import make_shortcut

gcc = make_shortcut("gcc")

#then use it like so:
gcc("-o guildenstern.exe rosencrantz.c")The invocation of thegccfunciton at the end will translate intogcc-oguildenstern.exe rosencrantz.cand be run.We can also use our shortcuts to inspect the input, output, and status
code of the command; the return value of a shortcut will be anenvoyresult. Check their
documentation for specifics, but basically you can see its output with:from pub.shortcuts import make_shortcut

echo = make_shortcut("echo")

out = echo("A conspiracy of cartographers")

assert out.std_out == "A conspiracy of cartographers\n"Thepub.shortcutsmodule also contains one utility function,newer. It simply accepts two arguments and returns True if the mtime
of the first is newer than the mtime of the second. Its entire defintion
follows:def newer(f1, f2):
    return stat(f1).st_mtime > stat(f2).st_mtimeThepubcommandThe pub command is best described by its--helpoutput:usage: pub [-h] [-l] [-f FILE] [task [task ...]]

Python Utility Belt v0.0.4

positional arguments:
  task                  the tasks to run

optional arguments:
  -h, --help            show this help message and exit
  -l                    list available tasks
  -f FILE, --pubfile FILE
                        The file to use as a pubfileContributingPlease do! Patches and issues will be gladly accepted.To runpub’s tests, just runpub test; you’ll need to have
installednosefirst.