AutoRebuild is a really simple CherryPy plugin that provides a hook point that is triggered when certain files change. It is similar to the Autoreloader plugin with the primary difference that it does not restart the engine and instead calls a function.

AutoRebuild also provides a ServiceStarter plugin that will start a service for you. As this tool was originally written to support things like sass and less where you want CSS changes to be reflected immediately and automatically, the ServiceStarter will let you start up something like "sass --watch".

More generally though, the ServiceStarter plugin can help you configure extra services you might need running in development or in testing. This avoids the necessity to use something like Foreman for service coordination in development.

AutoRebuild Usage

Here is a simple example:

import cherrypy
from autorebuild import AutoRebuild
from subprocess import call

from myapp import MyApp

def build_css():
    call(['make', 'css'])

# Create our plugin and attach it to the engine object so we can
# configure it with the cherrypy.config
cherrypy.engine.autorebuild = AutoRebuild(cherrypy.engine)

# Update our config with a glob expression to find some sass css
# files and call our build command defined in a make file to rebuild
# them
        'engine.autorebuild.on': True,
        'engine.autorebuild.taskmap': {'*.scss': build_css}})

# Start things up
cherrypy.tree.mount(MyApp(), '/')

Pretty simple.

ServiceStarter Example

Here is a simple example:

import cherrypy

class Root(object):
    def index(self):
        return 'Hello World!' = True

# Adding a service starter instance
cherrypy.engine.projserver = ServiceStarter(cherrypy.engine)

# Configure the stdlib simple server to run on port 9000 in the
# current directory
        'engine.projserver.cmd': 'python -m SimpleHTTPServer 9000'

cherrypy.tree.mount(Root(), '/')

Assuming you run this in the root of your source, you can now visit http://localhost:9000 to see the actual Python files.


A developer asked me if there was a good way to force CherryPy to restart and rebuild some sass files when the files changed. Knowing that the Autoreloader plugin already existed it seemed trivial to implement. The immediate solution was to simply use the 'sass --watch' command in a foreman procfile, but thinking about it, it seemed pretty silly when you could do it in CherryPy relatively easily and avoid having to depend on something like foreman all together.

I then realized there were tools like CodeKit people were actually selling to do this for you and it seemed ridiculous that there wasn't an easy way to do this in CherryPy. Fortunately, thanks to the WSPBus in CherryPy, it was a breeze.