Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix version-check. #489

Merged
merged 3 commits into from
May 29, 2019
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: 2 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 28 additions & 20 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ? {
Expand Down Expand Up @@ -57,6 +56,7 @@

package { 'virtualenv':
ensure => $venv_ensure,
name => "${python}-virtualenv",
require => Package['python'],
}

Expand Down Expand Up @@ -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',
}
Expand All @@ -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' |>
}
Expand All @@ -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 {
Expand Down Expand Up @@ -268,25 +268,33 @@
}
}

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' |> {
name => $pip_package,
category => $pip_category,
}

Python::Pip <| |> {
pip_provider => $pip_provider,
}

Package <| title == 'virtualenv' |> {
name => $virtualenv_package,
}
Expand Down
10 changes: 5 additions & 5 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down Expand Up @@ -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}",
Expand Down
2 changes: 1 addition & 1 deletion manifests/pip/bootstrap.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand Down
4 changes: 2 additions & 2 deletions manifests/requirements.pp
Original file line number Diff line number Diff line change
Expand Up @@ -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 ? {
Expand Down
11 changes: 11 additions & 0 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down