ReleaseEngineering/PuppetAgain/Modules/python: Difference between revisions

No edit summary
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 1: Line 1:
This module handles installing Python virtualenvs containing Python packages.  See [[ReleaseEngineering/How To/Install a Python Virtualenv with Puppet]] for a tutorial reference to using the module.
This module handles all things Python.


= Usage =
= python::user_pip_conf =
 
This define sets up a .pip/pip.conf for the named user that directs pip to install from the [[ReleaseEngineering/PuppetAgain/Python|python]] repository, including searching all puppetmasters in case one is down.  It takes an optional ''$homedir'' to specify the user's homedir, with the default being in ''/home''.  This define should generally be used from ''user'' module classes.  See e.g., ''user::root'' for an example.
 
= python::virtualenv =
 
This class installs Python virtualenvs containing Python packages.  See [[ReleaseEngineering/How To/Install a Python Virtualenv with Puppet]] for a tutorial reference to using the module.
 
== Usage ==


The main interface used here is <tt>python::virtualenv</tt>.  It takes the following parameters:
The main interface used here is <tt>python::virtualenv</tt>.  It takes the following parameters:
Line 7: Line 15:
;python: The python to use to build the virtualenv (mandatory)
;python: The python to use to build the virtualenv (mandatory)
;ensure: present (default) or absent
;ensure: present (default) or absent
;require: resources to require before making the virtualenv (e.g., your preferred python)
;packages: array of packages to include, in the format ''pkgname==version''.  Include all required packages - dependencies are not followed.  Running ''pip freeze'' in a test virtualenv can help determine this list (mandatory)
;packages: array of packages to include, in the format ''pkgname==version''.  Include all required packages - dependencies are not followed.  Running ''pip freeze'' in a test virtualenv can help determine this list (mandatory)
;user: user that should own the virtualenv (default root/admin)
;user: user that should own the virtualenv (default root/admin)
Line 12: Line 21:
Note that the python, user, and group attributes only have an effect when the virtualenv is created.  Packages can be added to the packages list, or their versions changed, but removing a package from the list will not result in puppet removing it from the virtualenv.
Note that the python, user, and group attributes only have an effect when the virtualenv is created.  Packages can be added to the packages list, or their versions changed, but removing a package from the list will not result in puppet removing it from the virtualenv.


= Example =
You can add dependencies on a virtualenv using the ''->'' operator.
 
== Example ==
   python::virtualenv {
   python::virtualenv {
       "/path/to/virtualenv":
       "/path/to/virtualenv":

Latest revision as of 22:29, 13 August 2012

This module handles all things Python.

python::user_pip_conf

This define sets up a .pip/pip.conf for the named user that directs pip to install from the python repository, including searching all puppetmasters in case one is down. It takes an optional $homedir to specify the user's homedir, with the default being in /home. This define should generally be used from user module classes. See e.g., user::root for an example.

python::virtualenv

This class installs Python virtualenvs containing Python packages. See ReleaseEngineering/How To/Install a Python Virtualenv with Puppet for a tutorial reference to using the module.

Usage

The main interface used here is python::virtualenv. It takes the following parameters:

title
The virtualenv directory to create
python
The python to use to build the virtualenv (mandatory)
ensure
present (default) or absent
require
resources to require before making the virtualenv (e.g., your preferred python)
packages
array of packages to include, in the format pkgname==version. Include all required packages - dependencies are not followed. Running pip freeze in a test virtualenv can help determine this list (mandatory)
user
user that should own the virtualenv (default root/admin)
group
group that should own the virtualenv (default root)

Note that the python, user, and group attributes only have an effect when the virtualenv is created. Packages can be added to the packages list, or their versions changed, but removing a package from the list will not result in puppet removing it from the virtualenv.

You can add dependencies on a virtualenv using the -> operator.

Example

 python::virtualenv {
     "/path/to/virtualenv":
         python => "/path/to/python",
         packages => [ "package==version", "mock==0.6.0",
                       "buildbot==0.8.0" ];
 }

or, to remove a virtualenv,

 python::virtualenv {
     "/path/to/virtualenv":
         ensure => absent;
 }

Notes

Specify the packages using the pypi "==" notation; do NOT use any other operator, e.g., "=>" or an unqualified package name.

An appropriate package file for the system must be available in the python package directory. For pure-python packages, this can be an sdist tarball or zip; for packages that include some compiled source (e.g., Twisted), things can get a bit more complicated - see here for more details.

It is up to the caller to ensure that Python is installed before the virtualenv is created.