Version information
Start using this module
Add this module to your Puppetfile:
mod 'counsyl-python', '0.9.11'
Learn more about managing modules with a PuppetfileDocumentation
python
This Puppet module installs the Python language runtime, and provides classes
for common Python packages and tools. In addition, an improved pip package
provider (pipx
) is included as well as custom types for Python
virtual environments (venv
) and packages inside virtual environments
(venv_package
).
By default, including the python
class installs Python, setuptools, and pip;
the python::virtualenv
class installs virtualenv.
Thus, to have Python, pip, and virtualenv installed on your system simply
place the following in your Puppet manifest:
include python
include python::virtualenv
This module supports Debian, RedHat, OpenBSD, Solaris, Windows, and Darwin platforms -- Windows users should read the Windows Notes.
Python Classes
python
Installs Python, setuptools, and pip using the system packages for the
platform, when available. If the system packages are too old, you may
bootstrap setuptools and pip using the built-in
ez_setup.py
template, e.g.:
class { 'python':
ez_setup => true,
}
python::virtualenv
Installs virtualenv, using the default system
package. If the system package is too old for your taste, tell it to be
installed using pip
by setting the package
parameter to false
:
include python
class { 'python::virtualenv':
package => false,
}
python::devel
Installs the Python development headers package for the system, useful
when you need to install packages with C extensions with pip
. For
example, to install PyCrypto
you could use the following (assuming a non-Windows platform):
include python
include python::devel
package { 'pycrypto':
ensure => installed,
provider => 'pip',
require => Class['python::devel'],
}
python::django
Installs Django in the system site-packages using pip
.
include python
include python::django
python::flask
Installs Flask in the system site-packages using pip
, for example:
include python
include python::flask
python::requests
Installs requests in the system site-packages using pip
, for example:
include python
include python::requests
Python Types
pipx
The pipx
package provider is an enhanced version of Puppet's own
pip
provider, specifically it:
- Implements the
install_options
feature, where you may specify the pip install options. - Uses HTTPS to query PyPI when setting
ensure
to 'latest' - Contains improvements for installing packages from version control
For example, assuming you had an internal PyPI mirror at
https://pypi.mycorp.com
, you could install the requests
package system-wide
from your mirror using the following:
package { 'requests':
ensure => installed,
provider => 'pipx',
install_options => [
{ '--index-url' => 'https://pypi.mycorp.com' },
],
}
venv
The venv
type enables the management of Python virtual environments.
The name of the venv
resource is the path to the virtual environment
-- for example to have your virtualenv in /srv/venv
, you'd use:
# Python and virtualenv are required to use `venv` type.
include python
include python::virtualenv
# Creating a virtualenv in /srv/venv.
venv { '/srv/venv': }
To have the virtualenv be owned by a user other than the one running
Puppet (typically root
), you can set the owner
and group
parameters
(these are not supported on Windows):
venv { '/srv/venv':
owner => 'justin',
group => 'users',
}
When using the owner
parameter Puppet will cast itself
as this user when installing packages with venv_package
-- this improves security especially when playing with unknown packages.
To have the virtualenv include the system site packages:
venv { '/srv/venv':
system_site_packages => true,
}
To delete the virtualenv from the system:
venv { '/srv/venv':
ensure => absent,
}
venv_package
This type installs packages in a Python virtual environment -- the title of
a venv_package
resource must contain the name of the package and the path
to to the virtual environment separated by the @
symbol. For example,
to install Django into the venv
defined above:
venv_package { 'Django@/srv/venv':
ensure => installed,
}
The venv
specifed after the @
will be automatically required.
Like the pipx
package provider, you may also specify install_options
, e.g.:
venv_package { 'Flask@/srv/venv':
ensure => installed,
install_options => [ { '--index-url' => 'https://pypi.mycorp.com' } ],
}
Just like with Puppet's own pip
provider, you can install using VCS --
for example, to install Flask
from GitHub (at the 0.8.1
version tag):
include sys::git
venv_package { 'Flask@/srv/venv':
ensure => '0.8.1',
source => 'git+https://github.com/mitsuhiko/flask',
require => Class['sys::git'],
}
Note: This had to be its own type (rather than a package provider) due to the fact that there can be multiple packages on a system in different virtual environments.
Windows Notes
Windows support requires the counsyl-windows
module. Because %Path%
updates aren't reflected in Puppet's current session,
you will see errors about not being able to find the pip
and/or virtualenv
commands -- running Puppet again should make these errors go away on a fresh
system. In addition, due to the nature of Windows platforms, customizations
should be done on the python::windows
class before including python
.
For example, to force the use the 32-bit version of Python 2.6.6 you would
use the following:
class { 'python::windows':
arch => 'i386',
version => '2.6.6',
}
include python
License
Apache License, Version 2.0
Contact
Justin Bronn justin@counsyl.com
Support
Please log tickets and issues at https://github.com/counsyl/puppet-python
0.9.11
IMPROVEMENTS
- Configurable pip version for Windows.
0.9.10
IMPROVEMENTS
- Do not upgrade package dependencies if not necessary (@michael-christen)
BUG FIXES
- Fix Puppet 4 incompatibility.
0.9.9
IMPROVEMENTS
- Uprade ez_setup.py to latest setuptools version (18.2).
FEATURES:
- Add support for OS X via Sam Kerr (GH-3)
- Add support for Redhat 7 from Amos Shapira
Dependencies
- counsyl/sys (>= 0.9.15)
Copyright 2013-2014 Counsyl, Inc. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ======================================================================== Portions of the `pipx` provider and `venv`/`venv_package` types and providers -- in other words the code in `lib/` -- is derived from Puppet: Copyright (C) 2005-2014 Puppet Labs Inc Puppet Labs can be contacted at: info@puppetlabs.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. ======================================================================== The code in `templates/ez_setup.py.erb` is from the setuptools package, maintained by the Python Packaging Authority's (PyPA): https://bitbucket.org/pypa/setuptools/raw/bootstrap/ez_setup.py Setuptools is released under the Python Software Foundation (PSF) License: Copyright (C) 2001-2014 Python Software Foundation; All Rights Reserved PSF LICENSE AGREEMENT FOR PYTHON 3.4.0 1. This LICENSE AGREEMENT is between the Python Software Foundation ("PSF"), and the Individual or Organization ("Licensee") accessing and otherwise using Python 3.4.0 software in source or binary form and its associated documentation. 2. Subject to the terms and conditions of this License Agreement, PSF hereby grants Licensee a nonexclusive, royalty-free, world-wide license to reproduce, analyze, test, perform and/or display publicly, prepare derivative works, distribute, and otherwise use Python 3.4.0 alone or in any derivative version, provided, however, that PSF’s License Agreement and PSF’s notice of copyright, i.e., "Copyright (C) 2001-2014 Python Software Foundation; All Rights Reserved" are retained in Python 3.4.0 alone or in any derivative version prepared by Licensee. 3. In the event Licensee prepares a derivative work that is based on or incorporates Python 3.4.0 or any part thereof, and wants to make the derivative work available to others as provided herein, then Licensee hereby agrees to include in any such work a brief summary of the changes made to Python 3.4.0. 4. PSF is making Python 3.4.0 available to Licensee on an "AS IS" basis. PSF MAKES NO REPRESENTATIONS OR WARRANTIES, EXPRESS OR IMPLIED. BY WAY OF EXAMPLE, BUT NOT LIMITATION, PSF MAKES NO AND DISCLAIMS ANY REPRESENTATION OR WARRANTY OF MERCHANTABILITY OR FITNESS FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF PYTHON 3.4.0 WILL NOT INFRINGE ANY THIRD PARTY RIGHTS. 5. PSF SHALL NOT BE LIABLE TO LICENSEE OR ANY OTHER USERS OF PYTHON 3.4.0 FOR ANY INCIDENTAL, SPECIAL, OR CONSEQUENTIAL DAMAGES OR LOSS AS A RESULT OF MODIFYING, DISTRIBUTING, OR OTHERWISE USING PYTHON 3.4.0, OR ANY DERIVATIVE THEREOF, EVEN IF ADVISED OF THE POSSIBILITY THEREOF. 6. This License Agreement will automatically terminate upon a material breach of its terms and conditions. 7. Nothing in this License Agreement shall be deemed to create any relationship of agency, partnership, or joint venture between PSF and Licensee. This License Agreement does not grant permission to use PSF trademarks or trade name in a trademark sense to endorse or promote products or services of Licensee, or any third party. 8. By copying, installing or otherwise using Python 3.4.0, Licensee agrees to be bound by the terms and conditions of this License Agreement.