Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
Enum['absent', 'present', 'latest'] $gunicorn = $python::params::gunicorn,
Boolean $manage_gunicorn = $python::params::manage_gunicorn,
$gunicorn_package_name = $python::params::gunicorn_package_name,
Optional[Enum['pip', 'scl', 'rhscl', '']] $provider = $python::params::provider,
Optional[Enum['pip', 'scl', 'rhscl', 'anaconda', '']] $provider = $python::params::provider,
$valid_versions = $python::params::valid_versions,
Hash $python_pips = { },
Hash $python_virtualenvs = { },
Expand All @@ -85,6 +85,8 @@
Hash $python_dotfiles = { },
Boolean $use_epel = $python::params::use_epel,
$rhscl_use_public_repository = $python::params::rhscl_use_public_repository,
Stdlib::Httpurl $anaconda_installer_url = $python::params::anaconda_installer_url,
Stdlib::Absolutepath $anaconda_install_path = $python::params::anaconda_install_path,
) inherits python::params {

$exec_prefix = $provider ? {
Expand Down
17 changes: 17 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,23 @@
Package <| tag == 'python-scl-package' |>
-> Package <| tag == 'python-pip-package' |>
}
'anaconda': {
$installer_path = '/var/tmp/anaconda_installer.sh'

file { $installer_path:
source => $::python::anaconda_installer_url,
mode => '0700',
}
-> exec { 'install_anaconda_python':
command => "${installer_path} -b -p ${::python::anaconda_install_path}",
creates => $::python::anaconda_install_path,
logoutput => true,
}
-> exec { 'install_anaconda_virtualenv':
command => "${::python::anaconda_install_path}/bin/pip install virtualenv",
creates => "${::python::anaconda_install_path}/bin/virtualenv",
}
}
default: {

package { 'pip':
Expand Down
2 changes: 2 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,6 @@

$rhscl_use_public_repository = true

$anaconda_installer_url = 'https://repo.anaconda.com/archive/Anaconda3-5.2.0-Linux-x86_64.sh'
$anaconda_install_path = '/opt/python'
}
18 changes: 11 additions & 7 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,6 @@
$log_dir = '/tmp',
$path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
) {

$python_provider = getparam(Class['python'], 'provider')
$python_version = getparam(Class['python'], 'version')

Expand All @@ -99,6 +98,11 @@
default => '',
}

$_path = $python_provider ? {
'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path),
default => $path,
}

# Parameter validation
if ! $virtualenv {
fail('python::pip: virtualenv parameter must not be empty')
Expand Down Expand Up @@ -213,7 +217,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
} else {
exec { "pip_install_${name}":
Expand All @@ -225,7 +229,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
}
} else {
Expand All @@ -242,7 +246,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
}
#
Expand All @@ -257,7 +261,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
}

Expand All @@ -272,7 +276,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
}

Expand All @@ -287,7 +291,7 @@
cwd => $cwd,
environment => $environment,
timeout => $timeout,
path => $path,
path => $_path,
}
}
}
Expand Down
7 changes: 6 additions & 1 deletion manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,11 @@
default => "${python::exec_prefix}pyvenv-${version}",
}

$_path = $::python::provider ? {
'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path),
default => $path,
}

if ( $systempkgs == true ) {
$system_pkgs_flag = '--system-site-packages'
} else {
Expand All @@ -85,7 +90,7 @@
command => "${virtualenv_cmd} --clear ${system_pkgs_flag} ${venv_dir}",
user => $owner,
creates => "${venv_dir}/bin/activate",
path => $path,
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
Expand Down
9 changes: 8 additions & 1 deletion manifests/virtualenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@
$virtualenv = undef
) {
include ::python
$python_provider = getparam(Class['python'], 'provider')
$anaconda_path = getparam(Class['python'], 'anaconda_install_path')

if $ensure == 'present' {
$python = $version ? {
Expand All @@ -105,6 +107,11 @@
default => "python${version}",
}

$_path = $python_provider ? {
'anaconda' => concat(["${anaconda_path}/bin"], $path),
default => $path,
}

if $virtualenv == undef {
$used_virtualenv = 'virtualenv'
} else {
Expand Down Expand Up @@ -175,7 +182,7 @@
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}",
user => $owner,
creates => "${venv_dir}/bin/activate",
path => $path,
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
Expand Down
10 changes: 10 additions & 0 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,16 @@
}
end

context 'anaconda' do
let(:params) { { provider: 'anaconda', anaconda_install_path: '/opt/test_path' } }

it {
is_expected.to contain_file('/var/tmp/anaconda_installer.sh')
is_expected.to contain_exec('install_anaconda_python').with_command('/var/tmp/anaconda_installer -b -p /opt/test_path')
is_expected.to contain_exec('install_anaconda_virtualenv').with_command('/opt/test_path/bin/pip install virtualenv')
}
end

# python::provider
context 'default' do
let(:params) { { provider: '' } }
Expand Down
15 changes: 15 additions & 0 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
id: 'root',
kernel: 'Linux',
lsbdistcodename: 'squeeze',
os: {
family: 'Debian'
},
osfamily: 'Debian',
operatingsystem: 'Debian',
operatingsystemrelease: '6',
Expand Down Expand Up @@ -77,6 +80,15 @@
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 ;}") }
end
end

describe 'path as' do
context 'adds anaconda path to pip invocation if provider is anaconda' do
let(:params) { {} }
let(:pre_condition) { 'class {"::python": provider => "anaconda", anaconda_install_path => "/opt/python3"}' }

it { is_expected.to contain_exec('pip_install_rpyc').with_path(['/opt/python3/bin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin']) }
end
end
end
end

Expand All @@ -89,6 +101,9 @@
id: 'root',
kernel: 'Linux',
lsbdistcodename: 'squeeze',
os: {
family: 'Debian'
},
osfamily: 'Debian',
operatingsystem: 'Debian',
operatingsystemrelease: '6',
Expand Down