From b88ea1947aafb9d8333d07a6927586baea51fb40 Mon Sep 17 00:00:00 2001 From: Robert Vincent Date: Thu, 23 May 2019 13:02:44 +0000 Subject: [PATCH 1/3] Fix version-check. --- manifests/init.pp | 4 ++-- manifests/install.pp | 48 ++++++++++++++++++++++---------------- manifests/pip.pp | 2 +- manifests/pip/bootstrap.pp | 2 +- manifests/pyvenv.pp | 4 ++-- manifests/requirements.pp | 4 ++-- spec/defines/pip_spec.rb | 2 +- 7 files changed, 37 insertions(+), 29 deletions(-) diff --git a/manifests/init.pp b/manifests/init.pp index 0a8b16c3..cd3132f5 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -65,9 +65,9 @@ default => '', } - unless $version =~ Pattern[/\A(python)?[0-9](\.[0-9])+/, + unless $version =~ Pattern[/\A(python)?[0-9](\.?[0-9])+/, /\Apypy\Z/, /\Asystem\Z/, /\Arh-python[0-9]{2}(?:-python)?\Z/] { - fail("version needs to be pypy, system or a version string like '3.5' or 'python3.5)") + fail("version needs to be pypy, system or a version string like '36', '3.6' or 'python3.6' )") } # Module compatibility check diff --git a/manifests/install.pp b/manifests/install.pp index 63c88079..70d2f0b6 100644 --- a/manifests/install.pp +++ b/manifests/install.pp @@ -6,13 +6,12 @@ # class python::install { - $python_version = getparam(Class['python'], 'version') - $python = $python_version ? { - 'system' => 'python', - 'pypy' => 'pypy', - /\A(python)?([0-9](\.?[0-9])+)/ => "python${2}", - /\Arh-python[0-9]{2}/ => $python_version, - default => "python${python::version}", + $python = $python::version ? { + 'system' => 'python', + 'pypy' => 'pypy', + /\A(python)?([0-9]+)/ => "python${2}", + /\Arh-python[0-9]{2}/ => $python::version, + default => "python${python::version}", } $pythondev = $facts['os']['family'] ? { @@ -57,6 +56,7 @@ package { 'virtualenv': ensure => $venv_ensure, + name => "${python}-virtualenv", require => Package['python'], } @@ -144,10 +144,10 @@ } 'rhscl': { # rhscl is RedHat SCLs from softwarecollections.org - if $::python::rhscl_use_public_repository { - $scl_package = "rhscl-${::python::version}-epel-${::operatingsystemmajrelease}-${::architecture}" + if $python::rhscl_use_public_repository { + $scl_package = "rhscl-${python::version}-epel-${::operatingsystemmajrelease}-${::architecture}" package { $scl_package: - source => "https://www.softwarecollections.org/en/scls/rhscl/${::python::version}/epel-${::operatingsystemmajrelease}-${::architecture}/download/${scl_package}.noarch.rpm", + source => "https://www.softwarecollections.org/en/scls/rhscl/${python::version}/epel-${::operatingsystemmajrelease}-${::architecture}/download/${scl_package}.noarch.rpm", provider => 'rpm', tag => 'python-scl-repo', } @@ -171,7 +171,7 @@ tag => 'python-pip-package', } - if $::python::rhscl_use_public_repository { + if $python::rhscl_use_public_repository { Package <| tag == 'python-scl-repo' |> -> Package <| tag == 'python-scl-package' |> } @@ -183,24 +183,24 @@ $installer_path = '/var/tmp/anaconda_installer.sh' file { $installer_path: - source => $::python::anaconda_installer_url, + 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, + 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", + command => "${python::anaconda_install_path}/bin/pip install virtualenv", + creates => "${python::anaconda_install_path}/bin/virtualenv", } } default: { case $facts['os']['family'] { 'AIX': { - if "${python_version}" =~ /^python3/ { #lint:ignore:only_variable_string - class { 'python::pip::bootstap': + if String($python::version) =~ /^python3/ { + class { 'python::pip::bootstrap': version => 'pip3', } } else { @@ -268,18 +268,22 @@ } } - if "${::python::version}" =~ /^python3/ { #lint:ignore:only_variable_string + if String($python::version) =~ /^python3/ { $pip_category = undef - $pip_package = 'python3-pip' + $pip_package = "${python}-pip" + $pip_provider = $python.regsubst(/^.*python3\.?/,'pip3.').regsubst(/\.$/,'') } elsif ($::osfamily == 'RedHat') and (versioncmp($::operatingsystemmajrelease, '7') >= 0) { $pip_category = undef $pip_package = 'python2-pip' + $pip_provider = pip2 } elsif $::osfamily == 'Gentoo' { $pip_category = 'dev-python' $pip_package = 'pip' + $pip_provider = 'pip' } else { $pip_category = undef $pip_package = 'python-pip' + $pip_provider = 'pip' } Package <| title == 'pip' |> { @@ -287,6 +291,10 @@ category => $pip_category, } + Python::Pip <| |> { + pip_provider => $pip_provider, + } + Package <| title == 'virtualenv' |> { name => $virtualenv_package, } diff --git a/manifests/pip.pp b/manifests/pip.pp index 569d62f9..1a49c456 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -85,7 +85,7 @@ } $_path = $python_provider ? { - 'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path), + 'anaconda' => concat(["${python::anaconda_install_path}/bin"], $path), default => $path, } diff --git a/manifests/pip/bootstrap.pp b/manifests/pip/bootstrap.pp index f5b18c02..eff7d568 100644 --- a/manifests/pip/bootstrap.pp +++ b/manifests/pip/bootstrap.pp @@ -13,7 +13,7 @@ Enum['pip', 'pip3'] $version = 'pip', Variant[Boolean, String] $manage_python = false, Optional[Stdlib::HTTPUrl] $http_proxy = undef, -) inherits ::python::params { +) inherits python::params { if $manage_python { include python } else { diff --git a/manifests/pyvenv.pp b/manifests/pyvenv.pp index 59b582ed..7807a6b3 100644 --- a/manifests/pyvenv.pp +++ b/manifests/pyvenv.pp @@ -65,8 +65,8 @@ $virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}" } - $_path = $::python::provider ? { - 'anaconda' => concat(["${::python::anaconda_install_path}/bin"], $path), + $_path = $python::provider ? { + 'anaconda' => concat(["${python::anaconda_install_path}/bin"], $path), default => $path, } diff --git a/manifests/requirements.pp b/manifests/requirements.pp index 8afe8568..d76d71a9 100644 --- a/manifests/requirements.pp +++ b/manifests/requirements.pp @@ -63,8 +63,8 @@ } $pip_env = $virtualenv ? { - 'system' => "${::python::exec_prefix} ${pip_provider}", - default => "${::python::exec_prefix} ${virtualenv}/bin/${pip_provider}", + 'system' => "${python::exec_prefix} ${pip_provider}", + default => "${python::exec_prefix} ${virtualenv}/bin/${pip_provider}", } $proxy_flag = $proxy ? { diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index 345de99b..68efdd53 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -87,7 +87,7 @@ 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"}' } + 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 From 791ede98b2cd3fb40a2954eaa4758877e53a6e26 Mon Sep 17 00:00:00 2001 From: Robert Vincent Date: Mon, 27 May 2019 17:10:28 +0000 Subject: [PATCH 2/3] Add single-quote to pip source. --- manifests/pip.pp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/manifests/pip.pp b/manifests/pip.pp index 1a49c456..06abce8d 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -157,16 +157,16 @@ $source = $url ? { false => "${pkgname}${extras_string}", - /^(\/|[a-zA-Z]\:)/ => $url, - /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ => $url, - default => "${url}#egg=${egg_name}", + /^(\/|[a-zA-Z]\:)/ => "'${url}'", + /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ => "'${url}'", + default => "'${url}#egg=${egg_name}'", } $pip_install = "${pip_env} --log ${log}/pip.log install" $pip_common_args = "${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}" # Explicit version out of VCS when PIP supported URL is provided - if $source =~ /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ { + if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ { if $ensure != present and $ensure != latest { exec { "pip_install_${name}": command => "${pip_install} ${install_args} ${pip_common_args}@${ensure}#egg=${egg_name}", From 645d247d7895adae23861c1a20b012ab4e90bd5c Mon Sep 17 00:00:00 2001 From: Robert Vincent Date: Wed, 29 May 2019 13:06:19 +0000 Subject: [PATCH 3/3] Add tests. --- spec/classes/python_spec.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/spec/classes/python_spec.rb b/spec/classes/python_spec.rb index 76d62c41..afebca6b 100644 --- a/spec/classes/python_spec.rb +++ b/spec/classes/python_spec.rb @@ -314,6 +314,17 @@ it { is_expected.to contain_class('python::install') } it { is_expected.to contain_package('pip').with_name('python2-pip') } + describe 'with python::version' do + context 'python36' do + let(:params) { { version: 'python36' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_package('pip').with_name('python36-pip') } + it { is_expected.to contain_package('python').with_name('python36') } + it { is_expected.to contain_package('python-dev').with_name('python36-devel') } + it { is_expected.to contain_package('virtualenv').with_name('python36-virtualenv') } + end + end describe 'with python::provider' do context 'scl' do describe 'with version' do