Showing with 145 additions and 40 deletions.
  1. +31 −0 .editorconfig
  2. +1 −1 .gitignore
  3. +1 −1 Modulefile
  4. +9 −4 README.md
  5. +35 −3 manifests/init.pp
  6. +14 −3 manifests/install.pp
  7. +1 −1 manifests/pip.pp
  8. +28 −12 manifests/requirements.pp
  9. +22 −10 manifests/virtualenv.pp
  10. +3 −5 spec/classes/python_spec.rb
31 changes: 31 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# This file is for unifying the coding style for different editors and IDEs
# editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_size = 4
tab_width = 4
indent_style = tab
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
indent_style = space
indent_size = 2

[*.txt]
trim_trailing_whitespace = false

[*.json]
insert_final_newline = false
indent_style = space
indent_size = 2

[*.yml]
insert_final_newline = false
indent_style = space
indent_size = 2
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ pkg/
Gemfile.lock
vendor/
spec/fixtures/
.vagrant/
.bundle/
.vagrant/
coverage/
2 changes: 1 addition & 1 deletion Modulefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name 'stankevich-python'
version '1.7.9'
version '1.7.10'
source 'git://github.com/stankevich/puppet-python.git'
author 'stankevich'
license 'Apache License, Version 2.0'
Expand Down
13 changes: 9 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Puppet module: python
# puppet-python #

[![Build Status](https://travis-ci.org/stankevich/puppet-python.svg?branch=master)](https://travis-ci.org/stankevich/puppet-python)

Expand All @@ -17,9 +17,13 @@ Currently, the changes you need to make are as follows:

## Installation

```shell
git submodule add https://github.com/stankevich/puppet-python.git /path/to/python
```
OR

``` shell
cd /etc/puppet/modules
git clone git://github.com/stankevich/puppet-python.git python
puppet module install stankevich-python
```

## Usage
Expand All @@ -30,7 +34,7 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic

**version** - Python version to install. Default: system default

**pip** - Install python-pip. Default: false
**pip** - Install python-pip. Default: true

**dev** - Install python-dev. Default: false

Expand Down Expand Up @@ -187,6 +191,7 @@ Manages Gunicorn virtual hosts.
## Authors

[Sergey Stankevich](https://github.com/stankevich)
[Shiva Poudel](https://github.com/shivapoudel)
[Ashley Penney](https://github.com/apenney)
[Marc Fournier](https://github.com/mfournier)
[Fotis Gimian](https://github.com/fgimian)
38 changes: 35 additions & 3 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,19 @@
# === Parameters
#
# [*version*]
# Python version to install. Default: system default
# Python version to install. Beware that valid values for this differ a) by
# the provider you choose and b) by the osfamily/operatingsystem you are using.
# Default: system default
# Allowed values:
# - provider == pip: everything pip allows as a version after the 'python=='
# - else: 'system', 'pypy', 3/3.3/...
# - Be aware that 'system' usually means python 2.X.
# - 'pypy' actually lets us use pypy as python.
# - 3/3.3/... means you are going to install the python3/python3.3/...
# package, if available on your osfamily.
#
# [*pip*]
# Install python-pip. Default: false
# Install python-pip. Default: true
#
# [*dev*]
# Install python-dev. Default: false
Expand All @@ -23,6 +32,11 @@
# [*manage_gunicorn*]
# Allow Installation / Removal of Gunicorn. Default: true
#
# [*provider*]
# What provider to use for installation of the packages, except gunicorn.
# Default: system default provider
# Allowed values: 'pip'
#
# === Examples
#
# class { 'python':
Expand All @@ -39,14 +53,32 @@
#
class python (
$version = 'system',
$pip = false,
$pip = true,
$dev = false,
$virtualenv = false,
$gunicorn = false,
$manage_gunicorn = true,
$provider = undef
) {

# validate inputs
if $provider != undef {
validate_re($provider, ['^pip$'], 'Only "pip" is a valid provider besides the system default.')
}

if $provider == 'pip' {
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
# this will only be checked if not pip, every other string would be rejected by provider check
} else {
validate_re($version, concat(['system', 'pypy'], $::python::install::valid_versions))
}

validate_bool($pip)
validate_bool($dev)
validate_bool($virtualenv)
validate_bool($gunicorn)
validate_bool($manage_gunicorn)

# Module compatibility check
$compatible = [ 'Debian', 'RedHat']
if ! ($::osfamily in $compatible) {
Expand Down
17 changes: 14 additions & 3 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@

class python::install {

$python = $python::version ? {
$valid_version = $::osfamily ? {
'RedHat' => ['3'],
'Debian' => ['3', '3.3']
}

$python = $::python::version ? {
'system' => 'python',
'pypy' => 'pypy',
default => "python${python::version}",
Expand All @@ -26,6 +31,13 @@
'Debian' => "${python}-dev"
}

# pip version: use only for installation via os package manager!
if $::python::version =~ /^3/ {
$pip = 'python3-pip'
} else {
$pip = 'python-pip'
}

$dev_ensure = $python::dev ? {
true => present,
default => absent,
Expand All @@ -46,12 +58,11 @@
pip: {
package { 'virtualenv': ensure => latest, provider => pip }
package { 'pip': ensure => latest, provider => pip }
package { $pythondev: ensure => latest }
package { "python==${python::version}": ensure => latest, provider => pip }
}
default: {
package { 'python-virtualenv': ensure => $venv_ensure }
package { 'python-pip': ensure => $pip_ensure }
package { $pip: ensure => $pip_ensure }
package { $pythondev: ensure => $dev_ensure }
package { $python: ensure => present }
}
Expand Down
2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
latest: {
# Latest version.
exec { "pip_install_${name}":
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${cwd}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${uninstall_args} ${install_editable} ${source} || ${pip_env} --log ${cwd}/pip.log install --upgrade ${proxy_flag} ${uninstall_args} ${install_editable} ${source} ;}",
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_env} --log ${cwd}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${cwd}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
user => $owner,
environment => $environment,
Expand Down
40 changes: 28 additions & 12 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,12 @@
# [*cwd*]
# The directory from which to run the "pip install" command. Default: undef
#
# [*extra_pip_args*]
# Extra arguments to pass to pip after the requirements file
#
# [*fix_requirements_owner*]
# Change owner and group of requirements file. Default: true
#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
Expand All @@ -49,21 +55,31 @@
# Fotis Gimian
#
define python::requirements (
$requirements = $name,
$virtualenv = 'system',
$owner = 'root',
$group = 'root',
$proxy = false,
$src = false,
$environment = [],
$forceupdate = false,
$cwd = undef,
$requirements = $name,
$virtualenv = 'system',
$owner = 'root',
$group = 'root',
$proxy = false,
$src = false,
$environment = [],
$forceupdate = false,
$cwd = undef,
$extra_pip_args = '',
$fix_requirements_owner = true
) {

if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
fail('python::pip: root user must be used when virtualenv is system')
}

if $fix_requirements_owner {
$owner_real = $owner
$group_real = $group
} else {
$owner_real = undef
$group_real = undef
}

$rootdir = $virtualenv ? {
'system' => '/',
default => $virtualenv,
Expand All @@ -90,8 +106,8 @@
file { $requirements:
ensure => present,
mode => '0644',
owner => $owner,
group => $group,
owner => $owner_real,
group => $group_real,
audit => content,
replace => false,
content => '# Puppet will install and/or update pip packages listed here',
Expand All @@ -100,7 +116,7 @@

exec { "python_requirements${name}":
provider => shell,
command => "${pip_env} --log ${rootdir}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements}",
command => "${pip_env} --log ${rootdir}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements} ${extra_pip_args}",
refreshonly => !$forceupdate,
timeout => 1800,
cwd => $cwd,
Expand Down
32 changes: 22 additions & 10 deletions manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
# [*timeout*]
# The maximum time in seconds the "pip install" command should take. Default: 1800
#
# [*extra_pip_args*]
# Extra arguments to pass to pip after requirements file. Default: blank
#
# === Examples
#
# python::virtualenv { '/var/www/project1':
Expand Down Expand Up @@ -78,7 +81,8 @@
$environment = [],
$path = [ '/bin', '/usr/bin', '/usr/sbin' ],
$cwd = undef,
$timeout = 1800
$timeout = 1800,
$extra_pip_args = ''
) {

if $ensure == 'present' {
Expand All @@ -89,6 +93,11 @@
default => "python${version}",
}

$virtualenv = $version ? {
'system' => 'virtualenv',
default => "virtualenv-${version}",
}

$proxy_flag = $proxy ? {
false => '',
default => "--proxy=${proxy}",
Expand Down Expand Up @@ -137,8 +146,10 @@
group => $group,
}



exec { "python_virtualenv_${venv_dir}":
command => "true ${proxy_command} && virtualenv ${system_pkgs_flag} -p ${python} ${venv_dir} && ${venv_dir}/bin/pip wheel --help > /dev/null 2>&1 && { ${venv_dir}/bin/pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag --upgrade pip ${distribute_pkg} || ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg} ;}",
command => "true ${proxy_command} && ${virtualenv} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${venv_dir}/bin/pip wheel --help > /dev/null 2>&1 && { ${venv_dir}/bin/pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag --upgrade pip ${distribute_pkg} || ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg} ;}",
user => $owner,
creates => "${venv_dir}/bin/activate",
path => $path,
Expand All @@ -150,7 +161,7 @@

if $requirements {
exec { "python_requirements_initial_install_${requirements}_${venv_dir}":
command => "${venv_dir}/bin/pip wheel --help > /dev/null 2>&1 && { ${venv_dir}/bin/pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag -r ${requirements}",
command => "${venv_dir}/bin/pip wheel --help > /dev/null 2>&1 && { ${venv_dir}/bin/pip wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${venv_dir}/bin/pip --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag -r ${requirements} ${extra_pip_args}",
refreshonly => true,
timeout => $timeout,
user => $owner,
Expand All @@ -160,13 +171,14 @@
}

python::requirements { "${requirements}_${venv_dir}":
requirements => $requirements,
virtualenv => $venv_dir,
proxy => $proxy,
owner => $owner,
group => $group,
cwd => $cwd,
require => Exec["python_virtualenv_${venv_dir}"],
requirements => $requirements,
virtualenv => $venv_dir,
proxy => $proxy,
owner => $owner,
group => $group,
cwd => $cwd,
require => Exec["python_virtualenv_${venv_dir}"],
extra_pip_args => $extra_pip_args,
}
}
} elsif $ensure == 'absent' {
Expand Down
8 changes: 3 additions & 5 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,9 @@
end
end

describe "with python::virtualenv" do
describe "without python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '', :virtualenv => '' }}
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("python-virtualenv").with_ensure('absent') }
end
end
Expand All @@ -87,7 +87,6 @@
it { is_expected.to contain_package("python-dev").with_ensure('present') }
end
context "default/empty" do
let (:params) {{ :dev => '' }}
it { is_expected.to contain_package("python-dev").with_ensure('absent') }
end
end
Expand Down Expand Up @@ -165,7 +164,7 @@

describe "with python::virtualenv" do
context "default/empty" do
let (:params) {{ :provider => '', :virtualenv => '' }}
let (:params) {{ :provider => '' }}
it { is_expected.to contain_package("python-virtualenv").with_ensure('absent') }
end
end
Expand All @@ -178,7 +177,6 @@
it { is_expected.to contain_package("python-devel").with_ensure('present') }
end
context "default/empty" do
let (:params) {{ :dev => '' }}
it { is_expected.to contain_package("python-devel").with_ensure('absent') }
end
end
Expand Down