Skip to content

Commit e784147

Browse files
committed
allow all python versions
Fixes issue voxpupuli#448, "Impossible to use version number in Ubuntu 16.04" 1) It does not make sense to restrict the allowed python versions per distribution. Newer distribution releases add new python versions and you can add repositories containing backports. 2) The List was outdated. Note: python version is needed for spec test
1 parent 250c7ad commit e784147

File tree

6 files changed

+20
-19
lines changed

6 files changed

+20
-19
lines changed

manifests/init.pp

+3-3
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,9 @@
6161
default => '',
6262
}
6363

64-
$allowed_versions = concat(['system', 'pypy'], $valid_versions)
65-
unless $version =~ Enum[$allowed_versions] {
66-
fail("version needs to be within${allowed_versions}")
64+
unless $version =~ Pattern[/\A(python)?[0-9](\.[0-9])+/,
65+
/\Apypy\Z/, /\Asystem\Z/] {
66+
fail("version needs to be pypy, system or a version string like '3.5' or 'python3.5)")
6767
}
6868

6969
# Module compatibility check

manifests/install.pp

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
$python = $python_version ? {
1111
'system' => 'python',
1212
'pypy' => 'pypy',
13-
default => "${python_version}", # lint:ignore:only_variable_string
13+
/\A(python)?([0-9](\.?[0-9])+)/ => "python${1}",
14+
default => "python${python::version}",
1415
}
1516

1617
$pythondev = $facts['os']['family'] ? {

manifests/params.pp

+1-7
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,7 @@
1212
$gunicorn = 'absent'
1313
$manage_gunicorn = true
1414
$provider = undef
15-
$valid_versions = $::osfamily ? {
16-
'RedHat' => ['3','27','33'],
17-
'Debian' => ['3', '3.3', '2.7'],
18-
'Suse' => [],
19-
'AIX' => ['python3'],
20-
'Gentoo' => ['2.7', '3.3', '3.4', '3.5']
21-
}
15+
$valid_versions = undef
2216

2317
if $::osfamily == 'RedHat' {
2418
if $::operatingsystem != 'Fedora' {

manifests/pyvenv.pp

+5-5
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@
3737

3838
if $ensure == 'present' {
3939
$python_version = $version ? {
40-
'system' => "$::python3_version",
41-
default => "${version}",
40+
'system' => $facts['python3_version'],
41+
default => $version,
4242
}
4343

4444
# Debian splits the venv module into a seperate package
4545
if ( $facts['os']['family'] == 'Debian'){
4646
$python3_venv_package="python${python_version}-venv"
47-
case $facts['os']['distro']['codename'] {
48-
'xenial','bionic','cosmic','disco',
47+
case $facts['lsbdistcodename'] {
48+
'xenial','bionic','cosmic','disco',
4949
'jessie','stretch','buster': {
5050
package {$python3_venv_package:
5151
before => File[$venv_dir],
@@ -56,7 +56,7 @@
5656
}
5757

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

spec/default_module_facts.yml

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
---
2+
python_version: "2.7"
3+
python3_version: ~

spec/defines/pyvenv_spec.rb

+6-3
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,18 @@
44
on_supported_os.each do |os, facts|
55
context("on #{os} ") do
66
let :facts do
7-
facts
7+
# python3 is required to use pyvenv
8+
facts.merge(
9+
python3_version: '3.4'
10+
)
811
end
912
let :title do
1013
'/opt/env'
1114
end
1215

1316
it {
1417
is_expected.to contain_file('/opt/env')
15-
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv --clear /opt/env')
18+
is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('pyvenv-3.4 --clear /opt/env')
1619
}
1720

1821
describe 'when ensure' do
@@ -28,6 +31,6 @@
2831
}
2932
end
3033
end
31-
end
34+
end # context
3235
end
3336
end

0 commit comments

Comments
 (0)