Skip to content

Commit f49763e

Browse files
author
grsakea
committed
Add support for Anaconda
1 parent 53839b0 commit f49763e

File tree

8 files changed

+72
-10
lines changed

8 files changed

+72
-10
lines changed

manifests/init.pp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
Enum['absent', 'present', 'latest'] $gunicorn = $python::params::gunicorn,
7777
Boolean $manage_gunicorn = $python::params::manage_gunicorn,
7878
$gunicorn_package_name = $python::params::gunicorn_package_name,
79-
Optional[Enum['pip', 'scl', 'rhscl', '']] $provider = $python::params::provider,
79+
Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']] $provider = $python::params::provider,
8080
$valid_versions = $python::params::valid_versions,
8181
Hash $python_pips = { },
8282
Hash $python_virtualenvs = { },
@@ -85,6 +85,8 @@
8585
Hash $python_dotfiles = { },
8686
Boolean $use_epel = $python::params::use_epel,
8787
$rhscl_use_public_repository = $python::params::rhscl_use_public_repository,
88+
Stdlib::Httpurl $anaconda_installer_url = $python::params::anaconda_installer_url,
89+
Stdlib::Absolutepath $anaconda_install_path = $python::params::anaconda_install_path,
8890
) inherits python::params {
8991

9092
$exec_prefix = $provider ? {

manifests/install.pp

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,23 @@
171171
Package <| tag == 'python-scl-package' |>
172172
-> Package <| tag == 'python-pip-package' |>
173173
}
174+
'anaconda': {
175+
$installer_path = '/var/tmp/anaconda_installer.sh'
176+
177+
file { $installer_path:
178+
source => $::python::anaconda_installer_url,
179+
mode => '0700',
180+
}
181+
-> exec { 'install_anaconda_python':
182+
command => "${installer_path} -b -p ${::python::anaconda_install_path}",
183+
creates => $::python::anaconda_install_path,
184+
logoutput => true,
185+
}
186+
-> exec { 'install_anaconda_virtualenv':
187+
command => "${::python::anaconda_install_path}/bin/pip install virtualenv",
188+
creates => "${::python::anaconda_install_path}/bin/virtualenv",
189+
}
190+
}
174191
default: {
175192

176193
package { 'pip':

manifests/params.pp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,6 @@
3535

3636
$rhscl_use_public_repository = true
3737

38+
$anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh'
39+
$anaconda_install_path = '/opt/python'
3840
}

manifests/pip.pp

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@
8787
$log_dir = '/tmp',
8888
$path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
8989
) {
90-
9190
$python_provider = getparam(Class['python'], 'provider')
9291
$python_version = getparam(Class['python'], 'version')
9392

@@ -99,6 +98,11 @@
9998
default => '',
10099
}
101100

101+
$_path = $python_provider ? {
102+
'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path),
103+
default => $path,
104+
}
105+
102106
# Parameter validation
103107
if ! $virtualenv {
104108
fail('python::pip: virtualenv parameter must not be empty')
@@ -213,7 +217,7 @@
213217
cwd => $cwd,
214218
environment => $environment,
215219
timeout => $timeout,
216-
path => $path,
220+
path => $_path,
217221
}
218222
} else {
219223
exec { "pip_install_${name}":
@@ -225,7 +229,7 @@
225229
cwd => $cwd,
226230
environment => $environment,
227231
timeout => $timeout,
228-
path => $path,
232+
path => $_path,
229233
}
230234
}
231235
} else {
@@ -242,7 +246,7 @@
242246
cwd => $cwd,
243247
environment => $environment,
244248
timeout => $timeout,
245-
path => $path,
249+
path => $_path,
246250
}
247251
}
248252
#
@@ -257,7 +261,7 @@
257261
cwd => $cwd,
258262
environment => $environment,
259263
timeout => $timeout,
260-
path => $path,
264+
path => $_path,
261265
}
262266
}
263267

@@ -272,7 +276,7 @@
272276
cwd => $cwd,
273277
environment => $environment,
274278
timeout => $timeout,
275-
path => $path,
279+
path => $_path,
276280
}
277281
}
278282

@@ -287,7 +291,7 @@
287291
cwd => $cwd,
288292
environment => $environment,
289293
timeout => $timeout,
290-
path => $path,
294+
path => $_path,
291295
}
292296
}
293297
}

manifests/pyvenv.pp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@
6868
default => "${python::exec_prefix}pyvenv-${version}",
6969
}
7070

71+
$_path = $::python::provider ? {
72+
'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path),
73+
default => $path,
74+
}
75+
7176
if ( $systempkgs == true ) {
7277
$system_pkgs_flag = '--system-site-packages'
7378
} else {
@@ -85,7 +90,7 @@
8590
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${venv_dir}",
8691
user => $owner,
8792
creates => "${venv_dir}/bin/activate",
88-
path => $path,
93+
path => $_path,
8994
cwd => '/tmp',
9095
environment => $environment,
9196
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

manifests/virtualenv.pp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@
9797
$virtualenv = undef
9898
) {
9999
include ::python
100+
$python_provider = getparam(Class['python'], 'provider')
101+
$anaconda_path = getparam(Class['python'], 'anaconda_install_path')
100102

101103
if $ensure == 'present' {
102104
$python = $version ? {
@@ -105,6 +107,11 @@
105107
default => "python${version}",
106108
}
107109

110+
$_path = $python_provider ? {
111+
'anaconda' => concat(["${anaconda_path}/bin"], $path),
112+
default => $path,
113+
}
114+
108115
if $virtualenv == undef {
109116
$used_virtualenv = 'virtualenv'
110117
} else {
@@ -175,7 +182,7 @@
175182
command => "true ${proxy_command} && ${virtualenv_cmd} ${system_pkgs_flag} -p ${python} ${venv_dir} && ${pip_cmd} --log ${venv_dir}/pip.log install ${pip_flags} --upgrade pip && ${pip_cmd} install ${pip_flags} --upgrade ${distribute_pkg}",
176183
user => $owner,
177184
creates => "${venv_dir}/bin/activate",
178-
path => $path,
185+
path => $_path,
179186
cwd => '/tmp',
180187
environment => $environment,
181188
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

spec/classes/python_spec.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,16 @@
183183
}
184184
end
185185

186+
context 'anaconda' do
187+
let(:params) { { provider: 'anaconda', anaconda_install_path: '/opt/test_path' } }
188+
189+
it {
190+
is_expected.to contain_file('/var/tmp/anaconda_installer.sh')
191+
is_expected.to contain_exec('install_anaconda_python').with_command('/var/tmp/anaconda_installer -b -p /opt/test_path')
192+
is_expected.to contain_exec('install_anaconda_virtualenv').with_command('/opt/test_path/bin/pip install virtualenv')
193+
}
194+
end
195+
186196
# python::provider
187197
context 'default' do
188198
let(:params) { { provider: '' } }

spec/defines/pip_spec.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
id: 'root',
1010
kernel: 'Linux',
1111
lsbdistcodename: 'squeeze',
12+
os: {
13+
family: 'Debian'
14+
},
1215
osfamily: 'Debian',
1316
operatingsystem: 'Debian',
1417
operatingsystemrelease: '6',
@@ -77,6 +80,15 @@
7780
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip show wheel > /dev/null 2>&1 || wheel_support_flag='--no-binary :all:'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --upgrade --index-url=http://www.example.com/simple/ rpyc ;}") }
7881
end
7982
end
83+
84+
describe 'path as' do
85+
context 'adds anaconda path to pip invocation if provider is anaconda' do
86+
let(:params) { {} }
87+
let(:pre_condition) { 'class {"::python": provider => "anaconda", anaconda_install_path => "/opt/python3"}' }
88+
89+
it { is_expected.to contain_exec('pip_install_rpyc').with_path(['/opt/python3/bin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin']) }
90+
end
91+
end
8092
end
8193
end
8294

@@ -89,6 +101,9 @@
89101
id: 'root',
90102
kernel: 'Linux',
91103
lsbdistcodename: 'squeeze',
104+
os: {
105+
family: 'Debian'
106+
},
92107
osfamily: 'Debian',
93108
operatingsystem: 'Debian',
94109
operatingsystemrelease: '6',

0 commit comments

Comments
 (0)