Showing with 37 additions and 7 deletions.
  1. +1 −1 Modulefile
  2. +3 −0 README.md
  3. +33 −6 manifests/pip.pp
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.6.6'
version '1.7.0'

author 'Sergey Stankevich'
license 'Apache License, Version 2.0'
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ Installs and manages python, python-dev, python-virtualenv and Gunicorn.

Installs and manages packages from pip.

**pkgname** - the name of the package to install. Required.

**ensure** - present/latest/absent. Default: present

**virtualenv** - virtualenv to run pip in. Default: system (no virtualenv)
Expand All @@ -69,6 +71,7 @@ Installs and manages packages from pip.
**uninstall_args** - Array of additional flags to pass to pip during uninstall. Default: none

python::pip { 'cx_Oracle':
pkgname => 'cx_Oracle',
virtualenv => '/var/www/project1',
owner => 'appuser',
proxy => 'http://proxy.domain.com:3128',
Expand Down
39 changes: 33 additions & 6 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,29 @@
default => "--proxy=${proxy}",
}

$grep_regex = $pkgname ? {
/==/ => "^${pkgname}\$",
default => "^${pkgname}==",
# If pkgname is not specified, use name (title) instead.
$use_pkgname = $pkgname ? {
undef => $name,
default => $pkgname
}

# Check if searching by explicit version.
if $ensure =~ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/ {
$grep_regex = "^${use_pkgname}==${ensure}\$"
} else {
$grep_regex = $use_pkgname ? {
/==/ => "^${use_pkgname}\$",
default => "^${use_pkgname}==",
}
}

$egg_name = $egg ? {
false => $pkgname,
false => $use_pkgname,
default => $egg
}

$source = $url ? {
false => $pkgname,
false => $use_pkgname,
default => "${url}#egg=${egg_name}",
}

Expand All @@ -108,7 +119,20 @@


case $ensure {
/^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/: {
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
# Explicit 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 ${install_args} \$wheel_support_flag ${proxy_flag} ${source}==${ensure}",
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
}
}

present: {
# Whatever version is available.
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 ${install_args} \$wheel_support_flag ${proxy_flag} ${source}",
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
Expand All @@ -119,17 +143,20 @@
}

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} ${source}",
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
user => $owner,
environment => $environment,
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
}
}

default: {
# Anti-action, uninstall.
exec { "pip_uninstall_${name}":
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${pkgname}",
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${use_pkgname}",
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
Expand Down