Skip to content

Commit d995c49

Browse files
committed
Added exec_prefix to clean up exec statements, particularly for scl
1 parent 2fde458 commit d995c49

6 files changed

Lines changed: 26 additions & 26 deletions

File tree

manifests/init.pp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,18 @@
7878

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

87+
$exec_prefix = $provider ? {
88+
'scl' => "scl enable ${version} -- ",
89+
'rhscl' => "scl enable ${version} -- ",
90+
default => '',
91+
}
92+
8793
validate_bool($pip)
8894
validate_bool($dev)
8995
validate_bool($virtualenv)

manifests/install.pp

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -88,17 +88,13 @@
8888
ensure => $dev_ensure,
8989
require => Package['scl-utils'],
9090
}
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",
91+
if $pip_ensure {
92+
exec { 'python-scl-pip-install':
93+
require => Package['scl-utils'],
94+
command => "${python::params::exec_prefix}easy_install pip",
95+
path => ['/usr/bin', '/bin'],
96+
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
97+
}
10298
}
10399
}
104100
rhscl: {
@@ -122,7 +118,7 @@
122118

123119
if $pip_ensure {
124120
exec { 'python-scl-pip-install':
125-
command => "${python::params::exec_prefix}easy_install pip",
121+
command => "${python::exec_prefix}easy_install pip",
126122
path => ['/usr/bin', '/bin'],
127123
creates => "/opt/rh/${python::version}/root/usr/bin/pip",
128124
}

manifests/pyvenv.pp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,9 @@
6161

6262
if $ensure == 'present' {
6363

64-
$virtualenv_cmd = $python::provider ? {
65-
'scl' => "scl enable ${python::version} -- pyvenv --clear",
66-
'rhscl' => "scl enable ${python::version} -- pyvenv --clear",
67-
default => $version ? {
68-
'system' => 'pyvenv',
69-
default => "pyvenv-${version}",
70-
}
64+
$virtualenv_cmd = $version ? {
65+
'system' => "${python::exec_prefix}pyvenv",
66+
default => "${python::exec_prefix}pyvenv-${version}",
7167
}
7268

7369
if ( $systempkgs == true ) {
@@ -84,7 +80,7 @@
8480
}
8581

8682
exec { "python_virtualenv_${venv_dir}":
87-
command => "${virtualenv_cmd} ${system_pkgs_flag} ${venv_dir}",
83+
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${venv_dir}",
8884
user => $owner,
8985
creates => "${venv_dir}/bin/activate",
9086
path => $path,

manifests/requirements.pp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,8 +94,8 @@
9494
}
9595

9696
$pip_env = $virtualenv ? {
97-
'system' => 'pip',
98-
default => "${virtualenv}/bin/pip",
97+
'system' => "${python::exec_prefix} pip",
98+
default => "${python::exec_prefix} ${virtualenv}/bin/pip",
9999
}
100100

101101
$proxy_flag = $proxy ? {

manifests/virtualenv.pp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,10 @@
153153
mode => $mode
154154
}
155155

156+
$pip_cmd = "${python::exec_prefix}${venv_dir}/bin/pip"
157+
156158
exec { "python_virtualenv_${venv_dir}":
157-
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} ;}",
159+
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} ;}",
158160
user => $owner,
159161
creates => "${venv_dir}/bin/activate",
160162
path => $path,
@@ -167,7 +169,7 @@
167169

168170
if $requirements {
169171
exec { "python_requirements_initial_install_${requirements}_${venv_dir}":
170-
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}",
172+
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}",
171173
refreshonly => true,
172174
timeout => $timeout,
173175
user => $owner,

spec/defines/pyvenv_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
it {
77
should contain_file( '/opt/env')
8-
should contain_exec( "python_virtualenv_/opt/env").with_command("pyvenv /opt/env")
8+
should contain_exec( "python_virtualenv_/opt/env").with_command("pyvenv --clear /opt/env")
99
}
1010

1111
describe 'when ensure' do

0 commit comments

Comments
 (0)