Showing with 125 additions and 27 deletions.
  1. +25 −13 README.md
  2. +12 −2 manifests/init.pp
  3. +73 −2 manifests/install.pp
  4. +4 −3 manifests/pyvenv.pp
  5. +2 −2 manifests/requirements.pp
  6. +5 −2 manifests/virtualenv.pp
  7. +3 −2 metadata.json
  8. +1 −1 spec/defines/pyvenv_spec.rb
38 changes: 25 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@

Puppet module for installing and managing python, pip, virtualenvs and Gunicorn virtual hosts.

**Version 1.1.x Notes**

Version `1.1.x` makes several fundamental changes to the core of this module, adding some additional features, improving performance and making operations more robust in general.

Please note that several changes have been made in `v1.1.x` which make manifests incompatible with the previous version. However, modifying your manifests to suit is trivial. Please see the notes below.

Currently, the changes you need to make are as follows:

* All pip definitions MUST include the owner field which specifies which user owns the virtualenv that packages will be installed in. Adding this greatly improves performance and efficiency of this module.
* You must explicitly specify pip => true in the python class if you want pip installed. As such, the pip package is now independent of the dev package and so one can exist without the other.

## Installation

```shell
Expand Down Expand Up @@ -175,7 +164,7 @@ Creates Python3 virtualenv.

**group** - Specify the group for this virtualenv

**path** - Specify the path that contains the pyvenv executable. Default: /bin/, /usr/bin, /usr/sbin
**path** - Specifies the PATH variable that contains `pyvenv` executable. Default: [ '/bin', '/usr/bin', '/usr/sbin' ]

**environment** - Specify any environment variables to use when creating pyvenv

Expand Down Expand Up @@ -278,6 +267,29 @@ python::python_pips:
virtualenv: "/opt/env2"
```
### Using SCL packages from RedHat or CentOS
To use this module with Linux distributions in the Red Hat family and python distributions
from softwarecollections.org, set python::provider to 'rhscl' and python::version to the name
of the collection you want to use (e.g., 'python27', 'python33', or 'rh-python34').
## Release Notes
**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.

**Version 1.1.x Notes**

Version `1.1.x` makes several fundamental changes to the core of this module, adding some additional features, improving performance and making operations more robust in general.

Please note that several changes have been made in `v1.1.x` which make manifests incompatible with the previous version. However, modifying your manifests to suit is trivial. Please see the notes below.

Currently, the changes you need to make are as follows:

* All pip definitions MUST include the owner field which specifies which user owns the virtualenv that packages will be installed in. Adding this greatly improves performance and efficiency of this module.
* You must explicitly specify pip => true in the python class if you want pip installed. As such, the pip package is now independent of the dev package and so one can exist without the other.

## Authors

[Sergey Stankevich](https://github.com/stankevich) | [Shiva Poudel](https://github.com/shivapoudel) | [Garrett Honeycutt](http://learnpuppet.com)
[Sergey Stankevich](https://github.com/stankevich) | [Shiva Poudel](https://github.com/shivapoudel) | [Peter Souter](https://github.com/petems) | [Garrett Honeycutt](http://learnpuppet.com)
14 changes: 12 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -67,21 +67,29 @@
$python_pips = { },
$python_virtualenvs = { },
$python_pyvenvs = { },
$python_requirements = { },
$use_epel = $python::params::use_epel,
) inherits python::params{

# validate inputs
if $provider != undef {
validate_re($provider, ['^pip$'], 'Only "pip" is a valid provider besides the system default.')
validate_re($provider, ['^(pip|scl|rhscl)$'], 'Only "pip", "rhscl", and "scl" are valid providers 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
} 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)
Expand All @@ -99,11 +107,13 @@
anchor { 'python::begin': } ->
class { 'python::install': } ->
class { 'python::config': } ->
Exec<| tag == 'python-virtualenv' |> ->
anchor { 'python::end': }

# Allow hiera configuration of python resources
create_resources('python::pip', $python_pips)
create_resources('python::pyvenv', $python_pyvenvs)
create_resources('python::virtualenv', $python_virtualenvs)
create_resources('python::requirements', $python_requirements)

}
75 changes: 73 additions & 2 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
'Suse' => "${python}-devel",
}

$python_virtualenv = $::lsbdistcodename ? {
'jessie' => 'virtualenv',
default => 'python-virtualenv',
}

# pip version: use only for installation via os package manager!
if $::python::version =~ /^3/ {
$pip = 'python3-pip'
Expand Down Expand Up @@ -56,6 +61,72 @@
package { 'pip': ensure => latest, provider => pip }
package { "python==${python::version}": ensure => latest, provider => pip }
}
scl: {
# SCL is only valid in the RedHat family. If RHEL, package must be
# enabled using the subscription manager outside of puppet. If CentOS,
# the centos-release-SCL will install the repository.
$install_scl_repo_package = $::operatingsystem ? {
'CentOS' => present,
default => absent,
}

package { 'centos-release-SCL':
ensure => $install_scl_repo_package,
before => Package['scl-utils'],
}
package { 'scl-utils': ensure => latest, }
package { $::python::version:
ensure => present,
require => Package['scl-utils'],
}
# This gets installed as a dependency anyway
# package { "${python::version}-python-virtualenv":
# ensure => $venv_ensure,
# require => Package['scl-utils'],
# }
package { "${python::version}-scldev":
ensure => $dev_ensure,
require => Package['scl-utils'],
}
if $pip_ensure {
exec { 'python-scl-pip-install':
require => Package['scl-utils'],
command => "${python::params::exec_prefix}easy_install pip",
path => ['/usr/bin', '/bin'],
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
}
}
}
rhscl: {
# rhscl is RedHat SCLs from softwarecollections.org
$scl_package = "rhscl-${::python::version}-epel-${::operatingsystemmajrelease}-${::architecture}"
package { $scl_package:
source => "https://www.softwarecollections.org/en/scls/rhscl/${::python::version}/epel-${::operatingsystemmajrelease}-${::architecture}/download/${scl_package}.noarch.rpm",
provider => 'rpm',
tag => 'python-scl-repo',
}

package { $::python::version:
ensure => present,
tag => 'python-scl-package',
}

package { "${python::version}-scldev":
ensure => $dev_ensure,
tag => 'python-scl-package',
}

if $pip_ensure {
exec { 'python-scl-pip-install':
command => "${python::exec_prefix}easy_install pip",
path => ['/usr/bin', '/bin'],
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
}
}
Package <| tag == 'python-scl-repo' |> ->
Package <| tag == 'python-scl-package' |> ->
Exec['python-scl-pip-install']
}
default: {
if $::osfamily == 'RedHat' {
if $pip_ensure == present {
Expand All @@ -67,11 +138,11 @@
if ($venv_ensure == present) and ($::operatingsystemrelease =~ /^6/) {
if $python::use_epel == true {
include 'epel'
Class['epel'] -> Package['python-virtualenv']
Class['epel'] -> Package[$python_virtualenv]
}
}
}
package { 'python-virtualenv': ensure => $venv_ensure }
package { $python_virtualenv: ensure => $venv_ensure }
package { $pip: ensure => $pip_ensure }
package { $pythondev: ensure => $dev_ensure }
package { $python: ensure => present }
Expand Down
7 changes: 4 additions & 3 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@
if $ensure == 'present' {

$virtualenv_cmd = $version ? {
'system' => 'pyvenv',
default => "pyvenv-${version}",
'system' => "${python::exec_prefix}pyvenv",
default => "${python::exec_prefix}pyvenv-${version}",
}

if ( $systempkgs == true ) {
Expand All @@ -80,14 +80,15 @@
}

exec { "python_virtualenv_${venv_dir}":
command => "${virtualenv_cmd} ${system_pkgs_flag} ${venv_dir}",
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${venv_dir}",
user => $owner,
creates => "${venv_dir}/bin/activate",
path => $path,
cwd => '/tmp',
environment => $environment,
unless => "grep '^[\\t ]*VIRTUAL_ENV=[\\\\'\\\"]*${venv_dir}[\\\"\\\\'][\\t ]*$' ${venv_dir}/bin/activate", #Unless activate exists and VIRTUAL_ENV is correct we re-create the virtualenv
require => File[$venv_dir],
tag => 'python-virtualenv',
}
} elsif $ensure == 'absent' {
file { $venv_dir:
Expand Down
4 changes: 2 additions & 2 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@
}

$pip_env = $virtualenv ? {
'system' => 'pip',
default => "${virtualenv}/bin/pip",
'system' => "${python::exec_prefix} pip",
default => "${python::exec_prefix} ${virtualenv}/bin/pip",
}

$proxy_flag = $proxy ? {
Expand Down
7 changes: 5 additions & 2 deletions manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,23 @@
mode => $mode
}

$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"

exec { "python_virtualenv_${venv_dir}":
command => "true ${proxy_command} && ${used_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} && ${used_virtualenv} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${pip_cmd} wheel --help > /dev/null 2>&1 && { ${pip_cmd} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; { ${pip_cmd} --log ${venv_dir}/pip.log install ${pypi_index} ${proxy_flag} \$wheel_support_flag --upgrade pip ${distribute_pkg} || ${pip_cmd} --log ${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=[\\\\'\\\"]*${venv_dir}[\\\"\\\\'][\\t ]*$' ${venv_dir}/bin/activate", #Unless activate exists and VIRTUAL_ENV is correct we re-create the virtualenv
require => File[$venv_dir],
tag => 'python-virtualenv',
}

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} ${extra_pip_args}",
command => "${pip_cmd} wheel --help > /dev/null 2>&1 && { ${pip_cmd} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_cmd} --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 Down
5 changes: 3 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "stankevich-python",
"version": "1.9.5",
"version": "1.9.6",
"author": "stankevich",
"summary": "Python Module",
"license": "Apache-2.0",
Expand All @@ -27,7 +27,8 @@
"operatingsystem": "Debian",
"operatingsystemrelease": [
"6",
"7"
"7",
"8"
]
},
{
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

it {
should contain_file( '/opt/env')
should contain_exec( "python_virtualenv_/opt/env").with_command("pyvenv /opt/env")
should contain_exec( "python_virtualenv_/opt/env").with_command("pyvenv --clear /opt/env")
}

describe 'when ensure' do
Expand Down