Fabric recipe: Delete pyc files before runserver starts


Here's a quick Fabric function that will clean out any pyc files in your Django project before firing up. It's nice to do this when you're building a site on your computer, since lingering pyc files can keep old code alive if you're not careful.

Fabric can also save you a keystroke or two. Heck, you could trim things down even more and name this function something like "rs."

def runserver(port=8000):
    Fire up the Django test server, after cleaning out any .pyc files.

    Example usage:
        $ fab runserver
        $ fab runserver:port=8001
    local("find . -name '*.pyc' -print0|xargs -0 rm", capture=False)
    local("./manage.py runserver %s" % port, capture=False)