From f49763ebc248076b59184aa08540b2efb4f51641 Mon Sep 17 00:00:00 2001 From: grsakea Date: Sat, 9 Jun 2018 14:17:42 +0000 Subject: [PATCH] Add support for Anaconda --- manifests/init.pp | 4 +++- manifests/install.pp | 17 +++++++++++++++++ manifests/params.pp | 2 ++ manifests/pip.pp | 18 +++++++++++------- manifests/pyvenv.pp | 7 ++++++- manifests/virtualenv.pp | 9 ++++++++- spec/classes/python_spec.rb | 10 ++++++++++ spec/defines/pip_spec.rb | 15 +++++++++++++++ 8 files changed, 72 insertions(+), 10 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index d0164ee1..258d0677 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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 = { }, @@ -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 ? { diff --git a/manifests/install.pp b/manifests/install.pp index a6dad661..1d1572f5 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -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': diff --git a/manifests/params.pp b/manifests/params.pp index bec6815c..5dacfc08 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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' } diff --git a/manifests/pip.pp b/manifests/pip.pp index b6d42278..fde7dc7e 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -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') @@ -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') @@ -213,7 +217,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } else { exec { "pip_install_${name}": @@ -225,7 +229,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } } else { @@ -242,7 +246,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } # @@ -257,7 +261,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } @@ -272,7 +276,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } @@ -287,7 +291,7 @@ cwd => $cwd, environment => $environment, timeout => $timeout, - path => $path, + path => $_path, } } } diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index ec659672..587f1baa 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -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 { @@ -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 diff --git a/manifests/virtualenv.pp b/manifests/virtualenv.pp index 638a750b..ad526678 100644 --- a/manifests/virtualenv.pp +++ b/manifests/virtualenv.pp @@ -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 ? { @@ -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 { @@ -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 diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index 84b266d5..a82c3d71 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -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: '' } } diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index 69d3837a..edc5fe93 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -9,6 +9,9 @@ id: 'root', kernel: 'Linux', lsbdistcodename: 'squeeze', + os: { + family: 'Debian' + }, osfamily: 'Debian', operatingsystem: 'Debian', operatingsystemrelease: '6', @@ -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 @@ -89,6 +101,9 @@ id: 'root', kernel: 'Linux', lsbdistcodename: 'squeeze', + os: { + family: 'Debian' + }, osfamily: 'Debian', operatingsystem: 'Debian', operatingsystemrelease: '6',