Showing with 35 additions and 13 deletions.
  1. +1 −1 Modulefile
  2. +5 −1 lib/facter/pip_version.rb
  3. +5 −2 lib/facter/python_version.rb
  4. +5 −1 lib/facter/virtualenv_version.rb
  5. +13 −5 manifests/pip.pp
  6. +6 −3 manifests/requirements.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.7.14'
version '1.7.15'
source 'git://github.com/stankevich/puppet-python.git'
author 'stankevich'
license 'Apache License, Version 2.0'
Expand Down
6 changes: 5 additions & 1 deletion lib/facter/pip_version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Make pip version available as a fact
# Works with pip loaded and without, pip installed using pip and package installed
require 'puppet'
pkg = Puppet::Type.type(:package).new(:name => "python-pip",:allow_virtual => 'false')
if Gem::Version.new(Facter.value(:puppetversion)) >= Gem::Version.new('3.6')
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false')
else
pkg = Puppet::Type.type(:package).new(:name => 'python-pip')
end
Facter.add("pip_version") do
has_weight 100
setcode do
Expand Down
7 changes: 5 additions & 2 deletions lib/facter/python_version.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
# Make python versions available as facts
# In lists default python and system python versions
require 'puppet'
pkg = Puppet::Type.type(:package).new(:name => "python",:allow_virtual => 'false')

if Gem::Version.new(Facter.value(:puppetversion)) >= Gem::Version.new('3.6')
pkg = Puppet::Type.type(:package).new(:name => 'python', :allow_virtual => 'false')
else
pkg = Puppet::Type.type(:package).new(:name => 'python')
end
Facter.add("system_python_version") do
setcode do
begin
Expand Down
6 changes: 5 additions & 1 deletion lib/facter/virtualenv_version.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
# Make virtualenv version available as a fact
# Works with virualenv loaded and without, pip installed and package installed
require 'puppet'
pkg = Puppet::Type.type(:package).new(:name => "virtualenv",:allow_virtual => 'false')
if Gem::Version.new(Facter.value(:puppetversion)) >= Gem::Version.new('3.6')
pkg = Puppet::Type.type(:package).new(:name => 'virtualenv', :allow_virtual => 'false')
else
pkg = Puppet::Type.type(:package).new(:name => 'virtualenv')
end
Facter.add("virtualenv_version") do
has_weight 100
setcode do
Expand Down
18 changes: 13 additions & 5 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,13 @@
# String. Any additional installation arguments that will be supplied
# when running pip install.
#
# [*uninstall args*]
# [*uninstall_args*]
# String. Any additional arguments that will be supplied when running
# pip uninstall.
#
# [*log_dir*]
# String. Log directory.
#
# === Examples
#
# python::pip { 'flask':
Expand All @@ -67,7 +70,7 @@
$install_args = '',
$uninstall_args = '',
$timeout = 1800,
$log_dir = '/',
$log_dir = '/tmp',
) {

# Parameter validation
Expand All @@ -80,6 +83,11 @@
}

$cwd = $virtualenv ? {
'system' => '/',
default => $virtualenv,
}

$log = $virtualenv ? {
'system' => $log_dir,
default => $virtualenv,
}
Expand Down Expand Up @@ -150,7 +158,7 @@
# 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} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${cwd}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
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 ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
cwd => $cwd,
Expand All @@ -163,7 +171,7 @@
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 \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${cwd}/pip.log install ${proxy_flag} ${install_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 ${log}/pip.log install \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
user => $owner,
cwd => $cwd,
Expand All @@ -176,7 +184,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} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${cwd}/pip.log install --upgrade ${proxy_flag} ${install_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 ${log}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
user => $owner,
cwd => $cwd,
Expand Down
9 changes: 6 additions & 3 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,9 @@
# [*fix_requirements_owner*]
# Change owner and group of requirements file. Default: true
#
# [*log_dir*]
# String. Log directory.
#
# === Examples
#
# python::requirements { '/var/www/project1/requirements.txt':
Expand All @@ -66,7 +69,7 @@
$cwd = undef,
$extra_pip_args = '',
$fix_requirements_owner = true,
$log_dir = '/',
$log_dir = '/tmp',
) {

if $virtualenv == 'system' and ($owner != 'root' or $group != 'root') {
Expand All @@ -81,7 +84,7 @@
$group_real = undef
}

$rootdir = $virtualenv ? {
$log = $virtualenv ? {
'system' => $log_dir,
default => $virtualenv,
}
Expand Down Expand Up @@ -117,7 +120,7 @@

exec { "python_requirements${name}":
provider => shell,
command => "${pip_env} --log ${rootdir}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements} ${extra_pip_args}",
command => "${pip_env} --log ${log}/pip.log install ${proxy_flag} ${src_flag} -r ${requirements} ${extra_pip_args}",
refreshonly => !$forceupdate,
timeout => 1800,
cwd => $cwd,
Expand Down