21 changes: 13 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,17 @@ puppet module install stankevich-python

Installs and manages python, python-pip, python-dev, python-virtualenv and Gunicorn.

**ensure** - Desired installation state for the Python package. Options are absent, present and latest. Default: present

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

**pip** - Install python-pip. Default: true
**pip** - Desired installation state for the python-pip package. Options are absent, present and latest. Default: present

**dev** - Install python-dev. Default: false
**dev** - Desired installation state for the python-dev package. Options are absent, present and latest. Default: present

**virtualenv** - Install python-virtualenv. Default: false
**virtualenv** - Desired installation state for the virtualenv package. Options are absent, present and latest. Default: present

**gunicorn** - Install Gunicorn. Default: false
**gunicorn** - Desired installation state for Gunicorn. Options are absent, present and latest. Default: present

**manage_gunicorn** - Allow Installation / Removal of Gunicorn. Default: true

Expand All @@ -67,10 +69,10 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic
```puppet
class { 'python' :
version => 'system',
pip => true,
dev => true,
virtualenv => true,
gunicorn => true,
pip => 'present',
dev => 'present',
virtualenv => 'present',
gunicorn => 'present',
}
```

Expand Down Expand Up @@ -306,6 +308,9 @@ of the collection you want to use (e.g., 'python27', 'python33', or 'rh-python34
## Release Notes
**Version 1.9.8 Notes**
The `pip`, `virtualenv` and `gunicorn` parameters of `Class['python']` have changed. These parameters now accept `absent`, `present` and `latest` rather than `true` and `false`. The boolean values are still supported and are equivalent to `present` and `absent` respectively. Support for these boolean parameters is deprecated and will be removed in a later release.

**Version 1.7.10 Notes**

Installation of python-pip previously defaulted to `false` and was not installed. This default is now `true` and python-pip is installed. To prevent the installation of python-pip specify `pip => false` as a parameter when instantiating the `python` puppet class.
Expand Down
28 changes: 26 additions & 2 deletions lib/facter/python_version.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
# Make python versions available as facts

def get_python_version(executable)
if Facter::Util::Resolution.which(executable)
results = Facter::Util::Resolution.exec("#{executable} -V 2>&1").match(/^.*(\d+\.\d+\.\d+)$/)
if results
results[1]
end
end
end

Facter.add("python_version") do
setcode do
if Facter::Util::Resolution.which('python')
Facter::Util::Resolution.exec('python -V 2>&1').match(/^.*(\d+\.\d+\.\d+)$/)[1]
get_python_version 'python'
end
end

Facter.add("python2_version") do
setcode do
default_version = get_python_version 'python'
if default_version.nil? or !default_version.start_with?('2')
get_python_version 'python2'
else
default_version
end
end
end

Facter.add("python3_version") do
setcode do
get_python_version 'python3'
end
end
2 changes: 1 addition & 1 deletion manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
Python::Virtualenv <| |> -> Python::Pip <| |>

if $python::manage_gunicorn {
if $python::gunicorn {
if $python::gunicorn != 'absent' {
Class['python::install'] -> Python::Gunicorn <| |>

Python::Gunicorn <| |> ~> Service['gunicorn']
Expand Down
73 changes: 50 additions & 23 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#
# === Parameters
#
# [*ensure*]
# Desired installation state for the Python package. Valid options are absent,
# present and latest. Default: present
#
# [*version*]
# 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.
Expand All @@ -17,24 +21,31 @@
# package, if available on your osfamily.
#
# [*pip*]
# Install python-pip. Default: true
# Desired installation state for python-pip. Boolean values are deprecated.
# Default: present
# Allowed values: 'absent', 'present', 'latest'
#
# [*dev*]
# Install python-dev. Default: false
# Desired installation state for python-dev. Boolean values are deprecated.
# Default: absent
# Allowed values: 'absent', 'present', 'latest'
#
# [*virtualenv*]
# Install python-virtualenv. Default: false, also accepts 'pip' which will
# install latest virtualenv from pip rather than package manager
# Desired installation state for python-virtualenv. Boolean values are
# deprecated. Default: absent
# Allowed values: 'absent', 'present', 'latest
#
# [*gunicorn*]
# Install Gunicorn. Default: false
# Desired installation state for Gunicorn. Boolean values are deprecated.
# Default: absent
# Allowed values: 'absent', 'present', 'latest'
#
# [*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
# What provider to use for installation of the packages, except gunicorn and
# Python itself. Default: system default provider
# Allowed values: 'pip'
#
# [*use_epel*]
Expand All @@ -44,10 +55,10 @@
#
# class { 'python':
# version => 'system',
# pip => true,
# dev => true,
# virtualenv => true,
# gunicorn => true,
# pip => 'present',
# dev => 'present',
# virtualenv => 'present',
# gunicorn => 'present',
# }
#
# === Authors
Expand All @@ -56,6 +67,7 @@
# Garrett Honeycutt <code@garretthoneycutt.com>
#
class python (
$ensure = $python::params::ensure,
$version = $python::params::version,
$pip = $python::params::pip,
$dev = $python::params::dev,
Expand All @@ -76,24 +88,39 @@
"Only 'pip', 'rhscl' and 'scl' are valid providers besides the system default. Detected provider is <${provider}>.")
}

if $provider == 'pip' {
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
} elsif ($provider == 'scl' or $provider == 'rhscl') {
validate_re($version, concat(['python33', 'python27', 'rh-python34'], $valid_versions))
} else {
validate_re($version, concat(['system', 'pypy'], $valid_versions))
}

$exec_prefix = $provider ? {
'scl' => "scl enable ${version} -- ",
'rhscl' => "scl enable ${version} -- ",
default => '',
}

validate_bool($pip)
validate_bool($dev)
validate_bool($virtualenv)
validate_bool($gunicorn)
validate_re($ensure, ['^(absent|present|latest)$'])
validate_re($version, concat(['system', 'pypy'], $valid_versions))

if $pip == false or $pip == true {
warning('Use of boolean values for the $pip parameter is deprecated')
} else {
validate_re($pip, ['^(absent|present|latest)$'])
}

if $virtualenv == false or $virtualenv == true {
warning('Use of boolean values for the $virtualenv parameter is deprecated')
} else {
validate_re($virtualenv, ['^(absent|present|latest)$'])
}

if $virtualenv == false or $virtualenv == true {
warning('Use of boolean values for the $virtualenv parameter is deprecated')
} else {
validate_re($virtualenv, ['^(absent|present|latest)$'])
}

if $gunicorn == false or $gunicorn == true {
warning('Use of boolean values for the $gunicorn parameter is deprecated')
} else {
validate_re($gunicorn, ['^(absent|present|latest)$'])
}

validate_bool($manage_gunicorn)
validate_bool($use_epel)

Expand Down
Loading