<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Straight Ornamental: Adventures with buildout</title>
    <link>http://grahamstratton.org/blog/public/articles/2007/06/27/adventures-with-buildout</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Ramblings from a rambler</description>
    <item>
      <title>Adventures with buildout</title>
      <description>&lt;p&gt;Recently I wanted to try some modifications to a Pylons project against the latest Pylons trunk without upgrading the system-installed Pylons, so I decided it was about time to try Buildout. Jim Fulton&amp;#8217;s buildout (or zc.buildout, since Jim likes to put things in namespaces), is a package to create development and deployment versions of software.  It&amp;#8217;s not in any way Zope-specific, and whilst it is written in Python primarily for installing Python programs, it&amp;#8217;s not really Python-specific either.&lt;/p&gt;


	&lt;p&gt;It is quite complex.  Maybe very complex.  But I think that this is only because deployment is a complex business.  I can imagine using nearly all the features in the &lt;a href="http:http://cheeseshop.python.org/pypi/zc.buildout/1.0.0b27#detailed-documentation"&gt;buildout docs&lt;/a&gt;, and a few more besides. But I did find a lack of really simple examples for us mortals.&lt;/p&gt;


	&lt;p&gt;The example I&amp;#8217;m going to give here is this: suppose you have a project in a repository. You can check it out, but when you&amp;#8217;ve done so you want a way to install all the dependencies, without affecting what&amp;#8217;s already installed on your system.&lt;/p&gt;


	&lt;p&gt;Buildout makes this easy. You need to add two files to your repository:&lt;/p&gt;


	&lt;ul&gt;
	&lt;li&gt;bootstrap.py which installs the latest buildout and setuptools&lt;/li&gt;
	&lt;/ul&gt;


	&lt;ul&gt;
	&lt;li&gt;buildout.cfg which contains the configuration for your install&lt;/li&gt;
	&lt;/ul&gt;


	&lt;p&gt;You can get bootstrap.py from the Zope Corp subversion server at http://svn.zope.org/zc.buildout/trunk/bootstrap/&lt;/p&gt;


	&lt;p&gt;Here&amp;#8217;s my buildout.cfg:&lt;/p&gt;


&lt;pre&gt;
[buildout]
parts = foxtrot

[foxtrot]
recipe = zc.recipe.egg
interpreter = python2.5
eggs = python-cjson
       nose
       twill
       pastescript
       pylons == 0.9.5
       sqlalchemy
#       pymssql
find-links = http://python.cx.hu/python-cjson/python-cjson-1.0.3x5.tar.gz
             http://www.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/p/py/pymssql/
&lt;/pre&gt;

	&lt;p&gt;So my buildout is simple. It only has one part, and the recipe for that is the simple egg recipe zc.recipe.egg. By specifying the interpreter option, I will get a python executable in my bin directory.  When I run it, the environment will contain all the specified packages. I have commented out pymssql because it has too many system dependencies.&lt;/p&gt;


	&lt;p&gt;Packages which are &lt;em&gt;explicitly&lt;/em&gt; specified (not installed as dependencies of other packages) and which define scripts to be installed will have those scripts written to ./bin/ instead of the system directory, and will work in the new environment. So I&amp;#8217;ve explicitly specified nose and pastescript, so that I end up with ./bin/nosetests and ./bin/paster working with this new environment. Cool, eh?&lt;/p&gt;


	&lt;p&gt;The &amp;#8216;find-links&amp;#8217; option is just a list of locations other than the cheeseshop in which to search for packages to install.&lt;/p&gt;


	&lt;p&gt;Once you have your configuration, setting up the environment is simple, if a little slow (mainly due to pypi being rather lethargic at the moment). First, run &lt;pre&gt;python bootstrap.py&lt;/pre&gt;, to install buildout itself. Then run ./bin/buildout, and everything should magically install. If you want to run it again, it will be &lt;em&gt;much&lt;/em&gt; faster with the -N option, which tells buildout not to look for new versions of packages if it already has a version matching the requirements. You can specify version for packages as you would with easy_install.&lt;/p&gt;


	&lt;p&gt;Well, I thought it all worked. But actually buildout doesn&amp;#8217;t seem to use the setuptools that it installs, despite it modifying the path:&lt;/p&gt;


&lt;pre&gt;
$ ./bin/buildout -N
Uninstalling foxtrot.
Installing foxtrot.
Getting distribution for 'Routes&amp;gt;=1.6.3'.
The required version of setuptools (&amp;gt;=0.6c6) is not available, and
can't be installed while this script is running. Please install
 a more recent version first.

(Currently using setuptools 0.6c5 (/usr/local/lib/python2.5/site-packages/setuptools-0.6c5-py2.5.egg))
error: Setup script exited with 2
&lt;/pre&gt;

	&lt;p&gt;Which is really odd, given that bin/buildout begins with:&lt;/p&gt;


&lt;pre&gt;
#!/usr/local/bin/python2.5

import sys
sys.path[0:0] = [
  '/Users/graham/development/pylons/foxtrot/eggs/zc.buildout-1.0.0b27-py2.5.egg',
  '/Users/graham/development/pylons/foxtrot/eggs/setuptools-0.6c6-py2.5.egg',
  ]
&lt;/pre&gt;

	&lt;p&gt;And I had another problem. I wanted to install the development version of pylons into my buildout. So I specified pylons==dev. But buildout gave an error since the version which got installed (0.9.6dev-r2373) wasn&amp;#8217;t the version requested. But then specifying pylons &amp;gt;= 0.9.6dev-r2373 worked.&lt;/p&gt;


	&lt;p&gt;Once you have everything running nicely in your buildout environment, you probably want to then deploy it somewhere. Creating consistent environments between systems in buildout&amp;#8217;s main purpose, so how do we do it?
It&amp;#8217;s described in detail in the buildout docs in the section &lt;a href="http://cheeseshop.python.org/pypi/zc.buildout/1.0.0b27#id124"&gt;controlling eggs used&lt;/a&gt;.&lt;/p&gt;


	&lt;p&gt;The configuration file buildout.cfg can contain sections specifying the versions of packages required. To find out what versions are being used, buildout can be run in verbose mode, using the -v option. Strangely, it seems that you then need to manually write these versions into the config file.&lt;/p&gt;


	&lt;p&gt;Hopefully this simple example will be enough to show the potential of buildout. The complete docs are very thorough and describe all the possible options.&lt;/p&gt;</description>
      <pubDate>Wed, 27 Jun 2007 22:22:00 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:81dbf791-77d1-4c90-a820-33c4113672ad</guid>
      <author>Graham Stratton</author>
      <link>http://grahamstratton.org/blog/public/articles/2007/06/27/adventures-with-buildout</link>
      <category>Python</category>
      <category>Software development</category>
      <category>Pylons</category>
    </item>
    <item>
      <title>"Adventures with buildout" by Graham</title>
      <description>&lt;p&gt;Apparently the correct way to install a dev version without getting the problem mentioned above is to use&lt;/p&gt;


	&lt;p&gt;Pylons==dev,&amp;gt;0.9.5&lt;/p&gt;</description>
      <pubDate>Mon, 02 Jul 2007 11:39:40 +0000</pubDate>
      <guid isPermaLink="false">urn:uuid:a085f17c-ab6d-4977-81c9-2416f534190d</guid>
      <link>http://grahamstratton.org/blog/public/articles/2007/06/27/adventures-with-buildout#comment-113</link>
    </item>
  </channel>
</rss>
