Skip to content

Commit ba07fbb

Browse files
authored
Merge pull request #466 from thaiphv/fix-python-pyvenv
Normalize Python version in `python::pyvenv`
2 parents 8b7c1e9 + 2f4f671 commit ba07fbb

File tree

5 files changed

+33
-20
lines changed

5 files changed

+33
-20
lines changed

manifests/install.pp

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
$python = $python_version ? {
1111
'system' => 'python',
1212
'pypy' => 'pypy',
13-
/\A(python)?([0-9](\.?[0-9])+)/ => "python${1}",
13+
/\A(python)?([0-9](\.?[0-9])+)/ => "python${2}",
1414
default => "python${python::version}",
1515
}
1616

@@ -74,19 +74,29 @@
7474
}
7575
}
7676

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

80-
Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>
82+
Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>
8183

82-
Package <| title == 'pip' |> {
83-
name => 'pip',
84-
provider => 'pip',
85-
}
86-
Package <| title == 'virtualenv' |> {
87-
name => 'virtualenv',
88-
provider => 'pip',
89-
require => Package[$pythondev],
84+
Package <| title == 'pip' |> {
85+
name => 'pip',
86+
provider => 'pip',
87+
}
88+
if $pythondev {
89+
Package <| title == 'virtualenv' |> {
90+
name => 'virtualenv',
91+
provider => 'pip',
92+
require => Package['python-dev'],
93+
}
94+
} else {
95+
Package <| title == 'virtualenv' |> {
96+
name => 'virtualenv',
97+
provider => 'pip',
98+
}
99+
}
90100
}
91101
}
92102
'scl': {

manifests/pip.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@
244244
# Unfortunately this is the smartest way of getting the latest available package version with pip as of now
245245
# Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns
246246
# more than one line with paretheses.
247-
$latest_version = join(["${pip_env} install ${proxy_flag} ${pkgname}==notreallyaversion 2>&1",
247+
$latest_version = join(["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${pkgname}==notreallyaversion 2>&1",
248248
' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"',
249249
' | tr -d "[:space:]"'])
250250

manifests/pyvenv.pp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,12 @@
4141
default => $version,
4242
}
4343

44+
$python_version_parts = split($python_version, '[.]')
45+
$normalized_python_version = sprintf('%s.%s', $python_version_parts[0], $python_version_parts[1])
46+
4447
# Debian splits the venv module into a seperate package
4548
if ( $facts['os']['family'] == 'Debian'){
46-
$python3_venv_package="python${python_version}-venv"
49+
$python3_venv_package="python${normalized_python_version}-venv"
4750
case $facts['lsbdistcodename'] {
4851
'xenial','bionic','cosmic','disco',
4952
'jessie','stretch','buster': {
@@ -57,9 +60,9 @@
5760

5861
# pyvenv is deprecated since 3.6 and will be removed in 3.8
5962
if (versioncmp($facts['python3_version'], '3.6') >=0) {
60-
$virtualenv_cmd = "${python::exec_prefix}python${python_version} -m venv"
63+
$virtualenv_cmd = "${python::exec_prefix}python${normalized_python_version} -m venv"
6164
} else {
62-
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${python_version}"
65+
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${normalized_python_version}"
6366
}
6467

6568
$_path = $::python::provider ? {

spec/classes/python_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
describe 'with python::provider' do
6363
context 'pip' do
64-
let(:params) { { provider: 'pip' } }
64+
let(:params) { { pip: 'present', provider: 'pip' } }
6565

6666
it {
6767
is_expected.to contain_package('virtualenv').with(
@@ -401,7 +401,7 @@
401401

402402
describe 'with python::provider' do
403403
context 'pip' do
404-
let(:params) { { provider: 'pip' } }
404+
let(:params) { { pip: 'present', provider: 'pip' } }
405405

406406
it {
407407
is_expected.to contain_package('virtualenv').with(

spec/defines/pyvenv_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
let :facts do
77
# python3 is required to use pyvenv
88
facts.merge(
9-
python3_version: '3.4'
9+
python3_version: '3.5.1'
1010
)
1111
end
1212
let :title do
@@ -15,7 +15,7 @@
1515

1616
it {
1717
is_expected.to contain_file('/opt/env')
18-
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.4 --clear /opt/env')
18+
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.5 --clear /opt/env')
1919
}
2020

2121
describe 'when ensure' do

0 commit comments

Comments
 (0)