Skip to content

Commit

Permalink
allow all python versions
Browse files Browse the repository at this point in the history
Fixes issue #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
  • Loading branch information
jradmacher committed Jan 2, 2019
1 parent 796680d commit 827f573
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 17 deletions.
5 changes: 3 additions & 2 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@
}

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

# Module compatibility check
Expand Down
3 changes: 2 additions & 1 deletion manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
$python = $::python::version ? {
'system' => 'python',
'pypy' => 'pypy',
default => "${python::version}", # lint:ignore:only_variable_string
/\A(python)?([0-9](\.[0-9])+)/ => "python${1}",
default => "python${python::version}",
}

$pythondev = $::osfamily ? {
Expand Down
7 changes: 1 addition & 6 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@
$gunicorn = 'absent'
$manage_gunicorn = true
$provider = undef
$valid_versions = $::osfamily ? {
'RedHat' => ['3','27','33'],
'Debian' => ['3', '3.3', '2.7'],
'Suse' => [],
'Gentoo' => ['2.7', '3.3', '3.4', '3.5']
}
$valid_versions = undef

if $::osfamily == 'RedHat' {
if $::operatingsystem != 'Fedora' {
Expand Down
10 changes: 5 additions & 5 deletions manifests/pyvenv.pp
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@

if $ensure == 'present' {
$python_version = $version ? {
'system' => "$::python3_version",
default => "${version}",
'system' => $facts['python3_version'],
default => $version,
}

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

# pyvenv is deprecated since 3.6 and will be removed in 3.8
if (versioncmp($::python3_version, '3.6') >=0) {
if (versioncmp($facts['python3_version'], '3.6') >=0) {
$virtualenv_cmd = "${python::exec_prefix}python${python_version} -m venv"
} else {
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${python_version}"
Expand Down
3 changes: 3 additions & 0 deletions spec/default_module_facts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
python_version: "2.7"
python3_version: ~
9 changes: 6 additions & 3 deletions spec/defines/pyvenv_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
on_supported_os.each do |os, facts|
context("on #{os} ") do
let :facts do
facts
# python3 is required to use pyvenv
facts.merge(
python3_version: '3.4'
)
end
let :title do
'/opt/env'
end

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

describe 'when ensure' do
Expand All @@ -28,6 +31,6 @@
}
end
end
end
end # context
end
end

0 comments on commit 827f573

Please sign in to comment.