Skip to content

Commit a14cf82

Browse files
author
Joshua Spence
committed
Fixes voxpupuli#240. Allow the ensure parameter to be specified of python::pip and python::virtualenv.
This is a bit rough... let me know if you are interested in this change and I will tidy it up.
1 parent 676f705 commit a14cf82

File tree

4 files changed

+115
-94
lines changed

4 files changed

+115
-94
lines changed

manifests/init.pp

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656
# Garrett Honeycutt <[email protected]>
5757
#
5858
class python (
59+
$ensure = $python::params::ensure,
5960
$version = $python::params::version,
6061
$pip = $python::params::pip,
6162
$dev = $python::params::dev,
@@ -76,23 +77,14 @@
7677
"Only 'pip', 'rhscl' and 'scl' are valid providers besides the system default. Detected provider is <${provider}>.")
7778
}
7879

79-
if $provider == 'pip' {
80-
validate_re($version, ['^(2\.[4-7]\.\d|3\.\d\.\d)$','^system$'])
81-
} elsif ($provider == 'scl' or $provider == 'rhscl') {
82-
validate_re($version, concat(['python33', 'python27', 'rh-python34'], $valid_versions))
83-
} else {
84-
validate_re($version, concat(['system', 'pypy'], $valid_versions))
85-
}
86-
8780
$exec_prefix = $provider ? {
8881
'scl' => "scl enable ${version} -- ",
8982
'rhscl' => "scl enable ${version} -- ",
9083
default => '',
9184
}
9285

93-
validate_bool($pip)
94-
validate_bool($dev)
95-
validate_bool($virtualenv)
86+
validate_re($ensure, ['^(absent|present|latest)$'])
87+
validate_re($version, concat(['system', 'pypy'], $valid_versions))
9688
validate_bool($gunicorn)
9789
validate_bool($manage_gunicorn)
9890
validate_bool($use_epel)

manifests/install.pp

Lines changed: 63 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -27,58 +27,70 @@
2727
'Suse' => "${python}-devel",
2828
}
2929

30-
$python_virtualenv = $::lsbdistcodename ? {
31-
'jessie' => 'virtualenv',
32-
default => 'python-virtualenv',
33-
}
34-
35-
# pip version: use only for installation via os package manager!
36-
if $::python::version =~ /^3/ {
37-
$pip = 'python3-pip'
38-
} else {
39-
$pip = 'python-pip'
40-
}
41-
4230
$dev_ensure = $python::dev ? {
4331
true => present,
44-
default => absent,
32+
false => absent,
33+
default => $python::dev,
4534
}
4635

4736
$pip_ensure = $python::pip ? {
4837
true => present,
49-
default => absent,
38+
false => absent,
39+
default => $python::pip,
5040
}
5141

5242
$venv_ensure = $python::virtualenv ? {
5343
true => present,
54-
default => absent,
44+
false => absent,
45+
default => $python::virtualenv,
46+
}
47+
48+
package { 'python':
49+
ensure => $python::ensure,
50+
name => $python,
51+
}
52+
53+
package { 'python-dev':
54+
ensure => $dev_ensure,
55+
name => $pythondev,
56+
}
57+
58+
package { 'pip':
59+
ensure => $pip_ensure,
60+
}
61+
62+
package { 'virtualenv':
63+
ensure => $venv_ensure,
5564
}
5665

57-
# Install latest from pip if pip is the provider
5866
case $python::provider {
5967
pip: {
60-
package { 'virtualenv': ensure => latest, provider => pip }
61-
package { 'pip': ensure => latest, provider => pip }
62-
package { "python==${python::version}": ensure => latest, provider => pip }
68+
Package <| title == 'pip' |> {
69+
name => 'pip',
70+
provider => 'pip',
71+
}
72+
Package <| title == 'virtualenv' |> {
73+
provider => 'pip',
74+
}
6375
}
6476
scl: {
6577
# SCL is only valid in the RedHat family. If RHEL, package must be
6678
# enabled using the subscription manager outside of puppet. If CentOS,
6779
# the centos-release-SCL will install the repository.
6880
$install_scl_repo_package = $::operatingsystem ? {
69-
'CentOS' => present,
70-
default => absent,
81+
'CentOS' => present,
82+
default => absent,
7183
}
7284

7385
package { 'centos-release-SCL':
7486
ensure => $install_scl_repo_package,
7587
before => Package['scl-utils'],
7688
}
77-
package { 'scl-utils': ensure => latest, }
78-
package { $::python::version:
79-
ensure => present,
80-
require => Package['scl-utils'],
89+
package { 'scl-utils':
90+
ensure => latest,
91+
before => Package['python'],
8192
}
93+
8294
# This gets installed as a dependency anyway
8395
# package { "${python::version}-python-virtualenv":
8496
# ensure => $venv_ensure,
@@ -106,46 +118,62 @@
106118
tag => 'python-scl-repo',
107119
}
108120

109-
package { $::python::version:
110-
ensure => present,
111-
tag => 'python-scl-package',
121+
Package <| title == 'python' |> {
122+
tag => 'python-scl-package',
112123
}
113124

114125
package { "${python::version}-scldev":
115126
ensure => $dev_ensure,
116127
tag => 'python-scl-package',
117128
}
118129

119-
if $pip_ensure {
130+
if $pip_ensure {
120131
exec { 'python-scl-pip-install':
121132
command => "${python::exec_prefix}easy_install pip",
122133
path => ['/usr/bin', '/bin'],
123134
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
124135
}
125136
}
137+
126138
Package <| tag == 'python-scl-repo' |> ->
127139
Package <| tag == 'python-scl-package' |> ->
128140
Exec['python-scl-pip-install']
129141
}
142+
130143
default: {
131144
if $::osfamily == 'RedHat' {
132145
if $pip_ensure == present {
133146
if $python::use_epel == true {
134147
include 'epel'
135-
Class['epel'] -> Package[$pip]
148+
Class['epel'] -> Package['pip']
136149
}
137150
}
138151
if ($venv_ensure == present) and ($::operatingsystemrelease =~ /^6/) {
139152
if $python::use_epel == true {
140153
include 'epel'
141-
Class['epel'] -> Package[$python_virtualenv]
154+
Class['epel'] -> Package['virtualenv']
142155
}
143156
}
144157
}
145-
package { $python_virtualenv: ensure => $venv_ensure }
146-
package { $pip: ensure => $pip_ensure }
147-
package { $pythondev: ensure => $dev_ensure }
148-
package { $python: ensure => present }
158+
159+
if $::python::version =~ /^3/ {
160+
$pip_package = 'python3-pip'
161+
} else {
162+
$pip_package = 'python-pip'
163+
}
164+
165+
$virtualenv_package = $::lsbdistcodename ? {
166+
'jessie' => 'virtualenv',
167+
default => 'python-virtualenv',
168+
}
169+
170+
Package <| title == 'pip' |> {
171+
name => $pip_package,
172+
}
173+
174+
Package <| title == 'virtualenv' |> {
175+
name => $virtualenv_package,
176+
}
149177
}
150178
}
151179

manifests/params.pp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
# The python Module default configuration settings.
44
#
55
class python::params {
6+
$ensure = 'present'
67
$version = 'system'
78
$pip = true
89
$dev = false

0 commit comments

Comments
 (0)