summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lib/facter/pip_version.rb19
-rw-r--r--lib/facter/python_version.rb28
-rw-r--r--lib/facter/virtualenv_version.rb19
-rw-r--r--manifests/init.pp6
-rw-r--r--manifests/install.pp21
-rw-r--r--manifests/pip.pp11
-rw-r--r--manifests/virtualenv.pp22
7 files changed, 110 insertions, 16 deletions
diff --git a/lib/facter/pip_version.rb b/lib/facter/pip_version.rb
new file mode 100644
index 0000000..48dd0bf
--- /dev/null
+++ b/lib/facter/pip_version.rb
@@ -0,0 +1,19 @@
+# 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")
+Facter.add("pip_version") do
+ has_weight 100
+ setcode do
+ Facter::Util::Resolution.exec('pip --version')
+ end
+end
+
+Facter.add("pip_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
diff --git a/lib/facter/python_version.rb b/lib/facter/python_version.rb
new file mode 100644
index 0000000..a2bdb26
--- /dev/null
+++ b/lib/facter/python_version.rb
@@ -0,0 +1,28 @@
+# Make python versions available as facts
+# In lists default python and system python versions
+require 'puppet'
+pkg = Puppet::Type.type(:package).new(:name => "python")
+
+Facter.add("system_python_version") do
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 100
+ setcode do
+ /^.*(\d+\.\d+\.\d+)$/.match(Facter::Util::Resolution.exec('python -V'))[1]
+ end
+end
+
+Facter.add("python_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
diff --git a/lib/facter/virtualenv_version.rb b/lib/facter/virtualenv_version.rb
new file mode 100644
index 0000000..c923b09
--- /dev/null
+++ b/lib/facter/virtualenv_version.rb
@@ -0,0 +1,19 @@
+# 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")
+Facter.add("virtualenv_version") do
+ has_weight 100
+ setcode do
+ Facter::Util::Resolution.exec('virtualenv --version')
+ end
+end
+
+Facter.add("virtualenv_version") do
+ has_weight 50
+ setcode do
+ if pkg.retrieve[pkg.property(:ensure)] != 'purged'
+ /^.*(\d+\.\d+\.\d+).*$/.match(pkg.retrieve[pkg.property(:ensure)])[1]
+ end
+ end
+end
diff --git a/manifests/init.pp b/manifests/init.pp
index c4e469d..9fe0420 100644
--- a/manifests/init.pp
+++ b/manifests/init.pp
@@ -14,7 +14,8 @@
# Install python-dev. Default: false
#
# [*virtualenv*]
-# Install python-virtualenv. Default: false
+# Install python-virtualenv. Default: false, also accepts 'pip' which will
+# install latest virtualenv from pip rather than package manager
#
# [*gunicorn*]
# Install Gunicorn. Default: false
@@ -38,7 +39,8 @@ class python (
$pip = false,
$dev = false,
$virtualenv = false,
- $gunicorn = false
+ $gunicorn = false,
+ $provider = undef,
) {
# Module compatibility check
diff --git a/manifests/install.pp b/manifests/install.pp
index 415092e..0d16659 100644
--- a/manifests/install.pp
+++ b/manifests/install.pp
@@ -10,8 +10,6 @@ class python::install {
/(?i:Debian|Ubuntu)/ => "${python}-dev"
}
- package { $python: ensure => present }
-
$dev_ensure = $python::dev ? {
true => present,
default => absent,
@@ -22,15 +20,26 @@ class python::install {
default => absent,
}
- package { $pythondev: ensure => $dev_ensure }
- package { 'python-pip': ensure => $pip_ensure }
-
$venv_ensure = $python::virtualenv ? {
true => present,
default => absent,
}
- package { 'python-virtualenv': ensure => $venv_ensure }
+ # Install latest from pip if pip is the provider
+ case $python::provider {
+ 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 { $pythondev: ensure => $dev_ensure }
+ package { $python: ensure => present }
+ }
+ }
$gunicorn_ensure = $python::gunicorn ? {
true => present,
diff --git a/manifests/pip.pp b/manifests/pip.pp
index 7b51439..bcb7911 100644
--- a/manifests/pip.pp
+++ b/manifests/pip.pp
@@ -92,6 +92,16 @@ define python::pip (
unless => "$pip_env freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
+ path => ["/usr/local/bin","/usr/bin","/bin", "/usr/sbin"],
+ }
+ }
+
+ latest: {
+ exec { "pip_install_${name}":
+ command => "$pip_env --log ${cwd}/pip.log install --upgrade ${proxy_flag} ${source}",
+ user => $owner,
+ environment => $environment,
+ path => ["/usr/local/bin","/usr/bin","/bin", "/usr/sbin"],
}
}
@@ -109,6 +119,7 @@ define python::pip (
onlyif => "$pip_env freeze | grep -i -e ${grep_regex}",
user => $owner,
environment => $environment,
+ path => ["/usr/local/bin","/usr/bin","/bin", "/usr/sbin"],
}
}
}
diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp
index 8486183..1fb55d6 100644
--- a/manifests/virtualenv.pp
+++ b/manifests/virtualenv.pp
@@ -15,6 +15,8 @@
#
# [*systempkgs*]
# Copy system site-packages into virtualenv. Default: don't
+# If virtualenv version < 1.7 this flag has no effect since
+# the system packages were not supported
#
# [*distribute*]
# Include distribute in the virtualenv. Default: true
@@ -72,7 +74,7 @@ define python::virtualenv (
$group = 'root',
$proxy = false,
$environment = [],
- $path = [ '/bin', '/usr/bin', '/usr/sbin' ],
+ $path = [ '/bin', '/usr/bin', '/usr/sbin','/usr/local/bin' ]
$cwd = undef,
$timeout = 1800
) {
@@ -96,9 +98,16 @@ define python::virtualenv (
default => "&& export http_proxy=${proxy}",
}
- $system_pkgs_flag = $systempkgs ? {
- false => '',
- default => '--system-site-packages',
+ # Virtualenv versions prior to 1.7 do not support the
+ # --system-site-packages flag, default off for prior versions
+ # Prior to version 1.7 the default was equal to --system-site-packages
+ # and the flag --no-site-packages had to be passed to do the opposite
+ if (( versioncmp($::virtualenv_version,'1.7') > 0 ) and ( $systempkgs == true )) {
+ $system_pkgs_flag = '--system-site-packages'
+ } elsif (( versioncmp($::virtualenv_version,'1.7') < 0 ) and ( $systempkgs == false )) {
+ $system_pkgs_flag = '--no-site-packages'
+ } else {
+ $system_pkgs_flag = ''
}
$distribute_pkg = $distribute ? {
@@ -113,10 +122,10 @@ define python::virtualenv (
exec { "python_virtualenv_${venv_dir}":
command => "mkdir -p ${venv_dir} ${proxy_command} && virtualenv ${system_pkgs_flag} -p ${python} ${venv_dir} && ${venv_dir}/bin/pip --log-file ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} --upgrade pip ${distribute_pkg}",
user => $owner,
- creates => "${venv_dir}/bin/activate",
path => $path,
cwd => "/tmp",
environment => $environment,
+ unless => "grep '^[ \t]*VIRTUAL_ENV=[\'\"]*/tmp[\"\']*[ \t]*$' /tmp/bin/activate", #Unless activate exists and VIRTUAL_ENV is correct we re-create the virtualenv
}
if $requirements {
@@ -139,7 +148,6 @@ define python::virtualenv (
require => Exec["python_virtualenv_${venv_dir}"],
}
}
-
} elsif $ensure == 'absent' {
file { $venv_dir:
@@ -148,7 +156,5 @@ define python::virtualenv (
recurse => true,
purge => true,
}
-
}
-
}