ReleaseEngineering/How To/Install a Python Virtualenv with Puppet

From MozillaWiki
Jump to: navigation, search

As of completion of bug 635007, Puppet can install virtualenvs for you. Here's how to make that happen.

Prep

First, you'll need to figure out:

  • which copy of Python you want to use as a basis for the virtualenv
  • the entire list of packages and versions that's required

The former will probably vary from slave to slave, although we should bring such variance to heel.

The latter is important because the python::virtualenv type does not follow dependencies. To figure this out, build yourself a virtualenv, install what you need using pip, and then use pip freeze to find a list of packages and versions, e.g.,

decorator==3.2.1
distribute==0.6.14
epydoc==3.0.1
mock==0.7.0b4
pytz==2010o
zope.interface==3.6.1


virtualenv installs 'distribute' for you, so there's no need to include it in your list. Aside from that, you'll need to get ahold of the tarballs for each of the required packages, e.g.,

decorator-3.2.1.tar.gz
epydoc-3.0.1.tar.gz
mock-0.7.0b4.tar.gz

and put those in the python/packages download directory, if they're not already there.

Manifest

Then, you'll need to put together a python::virtualenv resource, e.g.,

python::virtualenv {
  "/my/virtualenv":
    python => "/usr/bin/python",
    packages => [ 'decorator==3.2.1', 'epydoc==3.0.1', 'mock==0.7.0b4',
                  'pytz==2010o', 'zope-interface==3.6.1' ];
}

the nodes on which that resource are instantiated will find themselves with an installed virtualenv. It's that easy!