Skip to content

Commit 0f10cea

Browse files
committed
Merge branch 'master' into doc-fix-for-pip-default
# Conflicts: # README.md
2 parents c2f3c16 + f2fea3f commit 0f10cea

14 files changed

Lines changed: 216 additions & 138 deletions

File tree

.fixtures.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
fixtures:
22
repositories:
33
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
4+
"epel": "git://github.com/stahnma/puppet-module-epel.git"
45
symlinks:
56
"python": "#{source_dir}"

.travis.yml

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
11
---
22
language: ruby
33
bundler_args: --without system_tests
4-
script: "bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
4+
script: "bundle exec metadata-json-lint metadata.json && bundle exec rake validate && bundle exec rake lint && bundle exec rake spec SPEC_OPTS='--format documentation'"
5+
rvm:
6+
- 1.9.3
7+
- 2.0.0
58
matrix:
6-
fast_finish: true
7-
include:
8-
- rvm: 1.8.7
9-
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.6.0"
10-
- rvm: 1.8.7
11-
env: PUPPET_GEM_VERSION="~> 2.7.0" FACTER_GEM_VERSION="~> 1.7.0"
12-
- rvm: 1.9.3
13-
env: PUPPET_GEM_VERSION="~> 3.0"
9+
exclude:
10+
- rvm: 2.0.0
11+
env: PUPPET_VERSION="~> 2.7.0"
1412
- rvm: 2.0.0
15-
env: PUPPET_GEM_VERSION="~> 3.0"
13+
env: PUPPET_VERSION="~> 3.1.0"
14+
- rvm: 1.9.3
15+
env: PUPPET_VERSION="~> 2.7.0"
16+
17+
sudo: false

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
source ENV['GEM_SOURCE'] || "https://rubygems.org"
22

33
group :development, :test do
4+
gem 'metadata-json-lint', :require => false
45
gem 'rake', :require => false
56
gem 'rspec-puppet', :require => false
67
gem 'puppetlabs_spec_helper', :require => false

Modulefile

Lines changed: 0 additions & 12 deletions
This file was deleted.

README.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic
3131

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

34+
**use_epel** - Boolean to determine if the epel class is used. Default: true
35+
3436
```puppet
3537
class { 'python' :
3638
version => 'system',
@@ -162,7 +164,7 @@ Creates Python3 virtualenv.
162164

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

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

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

@@ -265,6 +267,13 @@ python::python_pips:
265267
virtualenv: "/opt/env2"
266268
```
267269
270+
### Using SCL packages from RedHat or CentOS
271+
272+
To use this module with the Red Hat Software Collections (SCL) or the CentOS
273+
equivalents, set python::provider to 'scl' and python::version to the name of
274+
the collection you want to use (e.g., 'python27', 'python33', or
275+
'rh-python34').
276+
268277
## Release Notes
269278
270279
**Version 1.7.10 Notes**
@@ -284,4 +293,4 @@ Currently, the changes you need to make are as follows:
284293

285294
## Authors
286295

287-
[Sergey Stankevich](https://github.com/stankevich) | [Shiva Poudel](https://github.com/shivapoudel)
296+
[Sergey Stankevich](https://github.com/stankevich) | [Shiva Poudel](https://github.com/shivapoudel) | [Peter Souter](https://github.com/petems) | [Garrett Honeycutt](http://learnpuppet.com)

lib/facter/pip_version.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
# Make pip version available as a fact
2-
# Works with pip loaded and without, pip installed using pip and package installed
3-
4-
facter_puppet_version = Facter.value(:puppetversion)
5-
facter_is_pe = Facter.value(:is_pe)
6-
7-
if facter_is_pe
8-
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0]
9-
end
10-
11-
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0)
12-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false')
13-
else
14-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip')
15-
end
162

173
Facter.add("pip_version") do
18-
has_weight 100
194
setcode do
205
if Facter::Util::Resolution.which('pip')
216
Facter::Util::Resolution.exec('pip --version 2>&1').match(/^pip (\d+\.\d+\.?\d*).*$/)[1]
227
end
238
end
249
end
25-
26-
Facter.add("pip_version") do
27-
has_weight 50
28-
setcode do
29-
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)])
30-
pkg.retrieve[pkg.property(:ensure)]
31-
end
32-
end
33-
end

lib/facter/python_version.rb

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,9 @@
11
# Make python versions available as facts
2-
# In lists default python and system python versions
3-
4-
facter_puppet_version = Facter.value(:puppetversion)
5-
facter_is_pe = Facter.value(:is_pe)
6-
7-
if facter_is_pe
8-
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0]
9-
end
10-
11-
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0)
12-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false')
13-
else
14-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip')
15-
end
16-
17-
Facter.add("system_python_version") do
18-
setcode do
19-
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)])
20-
pkg.retrieve[pkg.property(:ensure)]
21-
end
22-
end
23-
end
242

253
Facter.add("python_version") do
26-
has_weight 100
274
setcode do
285
if Facter::Util::Resolution.which('python')
296
Facter::Util::Resolution.exec('python -V 2>&1').match(/^.*(\d+\.\d+\.\d+)$/)[1]
307
end
318
end
329
end
33-
34-
Facter.add("python_version") do
35-
has_weight 50
36-
setcode do
37-
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)])
38-
pkg.retrieve[pkg.property(:ensure)]
39-
end
40-
end
41-
end

lib/facter/virtualenv_version.rb

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,9 @@
11
# Make virtualenv version available as a fact
2-
# Works with virualenv loaded and without, pip installed and package installed
3-
4-
facter_puppet_version = Facter.value(:puppetversion)
5-
facter_is_pe = Facter.value(:is_pe)
6-
7-
if facter_is_pe
8-
facter_puppet_version = facter_puppet_version.to_s.split(' ')[0]
9-
end
10-
11-
if (Puppet::Util::Package.versioncmp(facter_puppet_version, '3.6') >= 0)
12-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip', :allow_virtual => 'false')
13-
else
14-
pkg = Puppet::Type.type(:package).new(:name => 'python-pip')
15-
end
162

173
Facter.add("virtualenv_version") do
18-
has_weight 100
194
setcode do
205
if Facter::Util::Resolution.which('virtualenv')
216
Facter::Util::Resolution.exec('virtualenv --version 2>&1').match(/^(\d+\.\d+\.?\d*).*$/)[0]
227
end
238
end
249
end
25-
26-
Facter.add("virtualenv_version") do
27-
has_weight 50
28-
setcode do
29-
unless [:absent,:purged].include?(pkg.retrieve[pkg.property(:ensure)])
30-
pkg.retrieve[pkg.property(:ensure)]
31-
end
32-
end
33-
end

manifests/init.pp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@
3737
# Default: system default provider
3838
# Allowed values: 'pip'
3939
#
40+
# [*use_epel*]
41+
# Boolean to determine if the epel class is used. Default: true
42+
#
4043
# === Examples
4144
#
4245
# class { 'python':
@@ -50,6 +53,7 @@
5053
# === Authors
5154
#
5255
# Sergey Stankevich
56+
# Garrett Honeycutt <[email protected]>
5357
#
5458
class python (
5559
$version = $python::params::version,
@@ -63,16 +67,18 @@
6367
$python_pips = { },
6468
$python_virtualenvs = { },
6569
$python_pyvenvs = { },
70+
$use_epel = $python::params::use_epel,
6671
) inherits python::params{
6772

6873
# validate inputs
6974
if $provider != undef {
70-
validate_re($provider, ['^pip$'], 'Only "pip" is a valid provider besides the system default.')
75+
validate_re($provider, ['^(pip|scl)$'], 'Only "pip" or "scl" are valid providers besides the system default.')
7176
}
7277

7378
if $provider == 'pip' {
7479
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
75-
# this will only be checked if not pip, every other string would be rejected by provider check
80+
} elsif $provider == 'scl' {
81+
validate_re($version, concat(['python33', 'python27', 'rh-python34'], $valid_versions))
7682
} else {
7783
validate_re($version, concat(['system', 'pypy'], $valid_versions))
7884
}
@@ -82,9 +88,10 @@
8288
validate_bool($virtualenv)
8389
validate_bool($gunicorn)
8490
validate_bool($manage_gunicorn)
91+
validate_bool($use_epel)
8592

8693
# Module compatibility check
87-
$compatible = [ 'Debian', 'RedHat']
94+
$compatible = [ 'Debian', 'RedHat', 'Suse' ]
8895
if ! ($::osfamily in $compatible) {
8996
fail("Module is not compatible with ${::operatingsystem}")
9097
}

manifests/install.pp

Lines changed: 58 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# == Define: python::install
1+
# == Class: python::install
22
#
33
# Installs core python packages
44
#
@@ -11,8 +11,8 @@
1111
# Sergey Stankevich
1212
# Ashley Penney
1313
# Fotis Gimian
14+
# Garrett Honeycutt <[email protected]>
1415
#
15-
1616
class python::install {
1717

1818
$python = $::python::version ? {
@@ -23,7 +23,13 @@
2323

2424
$pythondev = $::osfamily ? {
2525
'RedHat' => "${python}-devel",
26-
'Debian' => "${python}-dev"
26+
'Debian' => "${python}-dev",
27+
'Suse' => "${python}-devel",
28+
}
29+
30+
$python_virtualenv = $::lsbdistcodename ? {
31+
'jessie' => 'virtualenv',
32+
default => 'python-virtualenv',
2733
}
2834

2935
# pip version: use only for installation via os package manager!
@@ -55,18 +61,62 @@
5561
package { 'pip': ensure => latest, provider => pip }
5662
package { "python==${python::version}": ensure => latest, provider => pip }
5763
}
64+
scl: {
65+
# SCL is only valid in the RedHat family. If RHEL, package must be
66+
# enabled using the subscription manager outside of puppet. If CentOS,
67+
# the centos-release-SCL will install the repository.
68+
$install_scl_repo_package = $::operatingsystem ? {
69+
'CentOS' => present,
70+
default => absent,
71+
}
72+
73+
package { 'centos-release-SCL':
74+
ensure => $install_scl_repo_package,
75+
before => Package['scl-utils'],
76+
}
77+
package { 'scl-utils': ensure => latest, }
78+
package { $::python::version:
79+
ensure => present,
80+
require => Package['scl-utils'],
81+
}
82+
# This gets installed as a dependency anyway
83+
# package { "${python::version}-python-virtualenv":
84+
# ensure => $venv_ensure,
85+
# require => Package['scl-utils'],
86+
# }
87+
package { "${python::version}-scldev":
88+
ensure => $dev_ensure,
89+
require => Package['scl-utils'],
90+
}
91+
# This looks absurd but I can't figure out a better way
92+
$pip_exec_onlyif = $pip_ensure ? {
93+
present => '/bin/true',
94+
default => '/bin/false',
95+
}
96+
exec { 'python-scl-pip-install':
97+
require => Package['scl-utils'],
98+
command => "scl enable ${python::version} -- easy_install pip",
99+
path => ['/usr/bin', '/bin'],
100+
onlyif => $pip_exec_onlyif,
101+
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
102+
}
103+
}
58104
default: {
59105
if $::osfamily == 'RedHat' {
60106
if $pip_ensure == present {
61-
include 'epel'
62-
Class['epel'] -> Package[$pip]
107+
if $python::use_epel == true {
108+
include 'epel'
109+
Class['epel'] -> Package[$pip]
110+
}
63111
}
64112
if ($venv_ensure == present) and ($::operatingsystemrelease =~ /^6/) {
65-
include 'epel'
66-
Class['epel'] -> Package['python-virtualenv']
113+
if $python::use_epel == true {
114+
include 'epel'
115+
Class['epel'] -> Package[$python_virtualenv]
116+
}
67117
}
68118
}
69-
package { 'python-virtualenv': ensure => $venv_ensure }
119+
package { $python_virtualenv: ensure => $venv_ensure }
70120
package { $pip: ensure => $pip_ensure }
71121
package { $pythondev: ensure => $dev_ensure }
72122
package { $python: ensure => present }
@@ -80,5 +130,4 @@
80130
}
81131
package { 'gunicorn': ensure => $gunicorn_ensure }
82132
}
83-
84133
}

0 commit comments

Comments
 (0)