Initialize a buildout for your project
Create a directory to share all buildout files and your Pylons project:
$ mkdir pylons_buildout $ cd pylons_buildout
Get the latest version of buildout's bootstrap script:
$ wget "http://svn.zope.org/*checkout*/zc.buildout/trunk/bootstrap/bootstrap.py"
Now you need to create the buildout configuration file:
$ touch buildout.cfg
You need to edit this file to tell buildout what to do. Buildout is highly configurable and not all options are described here. Here is a simple example to install Pylons with all dependencies:
[buildout] # The main section. # Tell buildout to not check new packages versions if we already # have one newest = false # The parts option define which sections buildout must install parts = pylons # Define wich section is used to get packages versions versions=versions # Tell buildout to also search packages at this url find-links = http://pylonshq.com/download/0.9.4 [versions] # You can force package's version here Pylons=0.9.7rc4 SQLAlchemy=0.5.2 [pylons] # The first part # The recipe tell buildout what to do with this section. # zc.recipe.egg just install some eggs in the eggs/ dir recipe = zc.recipe.egg # You need at least nose, PasteScript and Pylons # You can add other dependencies here eggs = nose PasteScript Pylons SQLAlchemy FormAlchemy
Now we have a clean buildout config. Let's bootstrap the buildout and run it:
$ python2.5 bootstrap.py $ ./bin/buildout
This will take a while. Time to make some coffee or read your favorite RSS feeds.
You now have two new binaries in the bin/ directory:
$ ls bin buildout* nosetests* paster*
All eggs can be found in eggs/:
$ ls eggs Beaker-1.2-py2.5.egg/ Pylons-0.9.7rc4-py2.5.egg/ FormAlchemy-1.1.1-py2.5.egg/ Routes-1.10.2-py2.5.egg/ ...
Creating and running a project
Lets create a pylons project with the newly created paster binary:
$ ./bin/paster create -t pylons myproject
Now you need to tell buildout to take care of your project. Edit the config file to add those two lines:
[buildout] develop = myproject [pylons] eggs= PasteScript Pylons ... myproject
You need to run buildout again:
$ ./bin/buildout
You may launch your project as usual:
$ ./bin/paster serve myproject/development.ini Starting server in PID 94325. serving on http://127.0.0.1:5000
Enjoy !
Usefull tips
Development vs production
You can have more than one .cfg file. eg: buildout.cfg for production (without the develop option) and development.cfg for development (with the develop option).
Remove the develop option from your buildout.cfg and create a development.cfg with:
[buildout] extends = buildout.cfg develop = myproject
You can add a find-links with the stable version of your project in buildout.cfg:
[buildout]
find-links =
http://pylonshq.com/download/0.9.4
http://myproject.repo.com/
To force buildout to use a specific config file use the -c option:
$ ./bin/buildout -c dev.cfg
Default configuration
You can have a default buildout configuration in ~/.buildout/default.cfg. A good idea it to put a eggs-directory in it to share eggs amongst your buildouts and avoid downloading the same egg multiple times:
[buildout] eggs-directory=/Users/gawel/eggs
Avoid loading site.py
If you have some conflict with packages installed on your system try to use the python's -S option:
$ python -S bootstrap.py $ python -S bin/buildout
Control pylons processes
You can use a recipe based on supervisor to control your pylons processes:
[buildout]
parts = ... supervisor
[supervisor]
recipe=collective.recipe.supervisor
programs=
10 app1 ${buildout:directory}/bin/paster [serve app1.ini] ${buildout:directory} true
20 app2 ${buildout:directory}/bin/paster [serve app2.ini] ${buildout:directory} true
30 app3 ${buildout:directory}/bin/paster [serve --server-name=server2 app2.ini] ${buildout:directory} true
This will add two scripts in the bin/ directory named supervisord and supervisorctl. Run supervisord to start the master deamon:
$ ./bin/supervisord
And then supervisorctl to control processes:
$ ./bin/supervisorctl status $ ./bin/supervisorctl restart app1 $ ./bin/supervisorctl restart all $ ./bin/supervisorctl shutdown
Using mod_wsgi with your buildout based project
You can have a look to this recipe if you plan to serve your pylons application with mod_wsgi.