Skip to content

Commit 4fbfc0d

Browse files
author
Thai Pham
committed
Normalize Python version in python::pyvenv
1 parent af0cfe1 commit 4fbfc0d

File tree

2 files changed

+8
-5
lines changed

2 files changed

+8
-5
lines changed

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/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)