Managing python installations

virtualenv

The basic building block for Python-based components is creation of virtualenvs (to separate package installations from each other):

self += VirtualEnv('2.7')
class batou.lib.python.VirtualEnv(version)

Creates a virtualenv for the given Python version in the working directory of the parent component. (Requires that pythonX.Y is in the PATH)

executable

Full path to the Python executable to create the virtualenv for (default: pythonX.Y based on the version attribute).

batou downloads a compatible version of virtualenv (depending on the Python version you need) to ensure everything works as expected and to avoid problems with incompatibilities or unexpected behaviours of whatever version might be installed already on the system. (virtualenv base installations are shared by all components for creating new virtualenvs, it is installed to work/.virtualenv).

Installing packages

Python packages are installed from a package index such as PyPI. batou uses pip or easy_install for this purpose (but that actually is an implementation detail and depends on the specifics of the Python and virtualenv version).

Packages must be added to a virtual environment.

venv = VirtualEnv('2.7')
self += venv
venv += Package('Sphinx', version='1.1.3')
class batou.lib.python.Package(package)

Install the Python package with the given name into the virtualenv of the parent component. Using Package requires that it is added to a VirtualEnv instance.

version

The version of the package to install (required).

install_options

List of options that are passed to pip/easy_install on the command line.

[Default: depends on the Python/virtualenv version in use]

check_package_is_module

Verify that the package is installed by trying to import it (more precisely, the first component of its dotted name). This is a stopgap against https://github.com/pypa/pip/issues/3, but should be pretty safe to disable if it causes trouble for specific packages (distribute is a notable example, since it installs a Python module named setuptools).

[Default: True]

timeout

A timeout (in seconds) that the installer should use to limit stalling network activity.

Only works when using pip.

[Default: equal to the environment’s timeout setting]

dependencies

Whether only the package itself or its dependencies should be installed.

[Default: True]

zc.buildout

batou has in-depth support for managing installations that use buildout. It automatically wraps them in a virtualenv, installs the appropriate buildout version, and takes care of running buildout whenever changes to configuration files makes it necessary. A typical usage example:

self += Buildout(python='2.7', version='2.2', setuptools='1.0',
                 additional_config=[Directory('profiles', source='profiles')])
class batou.lib.buildout.Buildout

Manage a buildout installation

python

Python version (required)

executable

Full path to the python executable to create the virtualenv for (used instead of pythonX.Y).

version

Version of zc.buildout to install (required)

setuptools

Version of setuptools to install into the virtualenv (must be appropriate to the buildout version, e.g. since 2.2 buildout requires setuptools, but some versions before that required distribute) (required)

distribute

Version of distribute to install into the virtualenv. Mutually exclusive with setuptools, of course.

config

If a different configuration file name than buildout.cfg should be used, pass in a File or Component instance.

additional_config

Optional list of component instances (e.g. File or Directory) that contain further configuration files (so Buildout knows when running buildout is needed).