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

Normalize Python version in python::pyvenv #466

Merged
merged 2 commits into from
Feb 27, 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
34 changes: 22 additions & 12 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
$python = $python_version ? {
'system' => 'python',
'pypy' => 'pypy',
/\A(python)?([0-9](\.?[0-9])+)/ => "python${1}",
/\A(python)?([0-9](\.?[0-9])+)/ => "python${2}",
default => "python${python::version}",
}

Expand Down Expand Up @@ -74,19 +74,29 @@
}
}

# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
include 'python::pip::bootstrap'
# Respect the $pip_ensure setting
unless $pip_ensure == 'absent' {
# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
include 'python::pip::bootstrap'

Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>
Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>

Package <| title == 'pip' |> {
name => 'pip',
provider => 'pip',
}
Package <| title == 'virtualenv' |> {
name => 'virtualenv',
provider => 'pip',
require => Package[$pythondev],
Package <| title == 'pip' |> {
name => 'pip',
provider => 'pip',
}
if $pythondev {
Package <| title == 'virtualenv' |> {
name => 'virtualenv',
provider => 'pip',
require => Package['python-dev'],
}
} else {
Package <| title == 'virtualenv' |> {
name => 'virtualenv',
provider => 'pip',
}
}
}
}
'scl': {
Expand Down
2 changes: 1 addition & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@
# Unfortunately this is the smartest way of getting the latest available package version with pip as of now
# Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns
# more than one line with paretheses.
$latest_version = join(["${pip_env} install ${proxy_flag} ${pkgname}==notreallyaversion 2>&1",
$latest_version = join(["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${pkgname}==notreallyaversion 2>&1",
' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"',
' | tr -d "[:space:]"'])

Expand Down
9 changes: 6 additions & 3 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,12 @@
default => $version,
}

$python_version_parts = split($python_version, '[.]')
$normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1])

# Debian splits the venv module into a seperate package
if ( $facts['os']['family'] == 'Debian'){
$python3_venv_package="python${python_version}-venv"
$python3_venv_package="python${normalized_python_version}-venv"
case $facts['lsbdistcodename'] {
'xenial','bionic','cosmic','disco',
'jessie','stretch','buster': {
Expand All @@ -57,9 +60,9 @@

# pyvenv is deprecated since 3.6 and will be removed in 3.8
if (versioncmp($facts['python3_version'], '3.6') >=0) {
$virtualenv_cmd = "${python::exec_prefix}python${python_version} -m venv"
$virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv"
} else {
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${python_version}"
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}"
}

$_path = $::python::provider ? {
Expand Down
4 changes: 2 additions & 2 deletions spec/classes/python_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@

describe 'with python::provider' do
context 'pip' do
let(:params) { { provider: 'pip' } }
let(:params) { { pip: 'present', provider: 'pip' } }

it {
is_expected.to contain_package('virtualenv').with(
Expand Down Expand Up @@ -384,7 +384,7 @@

describe 'with python::provider' do
context 'pip' do
let(:params) { { provider: 'pip' } }
let(:params) { { pip: 'present', provider: 'pip' } }

it {
is_expected.to contain_package('virtualenv').with(
Expand Down
4 changes: 2 additions & 2 deletions spec/defines/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
let :facts do
# python3 is required to use pyvenv
facts.merge(
python3_version: '3.4'
python3_version: '3.5.1'
)
end
let :title do
Expand All @@ -15,7 +15,7 @@

it {
is_expected.to contain_file('/opt/env')
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.4 --clear /opt/env')
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env')
}

describe 'when ensure' do
Expand Down