Skip to content

Commit af0cfe1

Browse files
authored
Merge pull request #451 from emetriq/allow_custom_versions
Allow custom python versions and environments
2 parents 995ca4e + 5ea5621 commit af0cfe1

File tree

7 files changed

+43
-17
lines changed

7 files changed

+43
-17
lines changed

manifests/init.pp

Lines changed: 3 additions & 3 deletions
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

Lines changed: 2 additions & 1 deletion
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

Lines changed: 1 addition & 7 deletions
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/pip.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,11 @@
7171
$python_provider = getparam(Class['python'], 'provider')
7272
$python_version = getparam(Class['python'], 'version')
7373

74+
if $virtualenv != 'system' {
75+
Python::Pyvenv <| |> -> Python::Pip[$name]
76+
Python::Virtualenv <| |> -> Python::Pip[$name]
77+
}
78+
7479
# Get SCL exec prefix
7580
# NB: this will not work if you are running puppet from scl enabled shell
7681
$exec_prefix = $python_provider ? {

manifests/pyvenv.pp

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,30 @@
3636
include ::python
3737

3838
if $ensure == 'present' {
39+
$python_version = $version ? {
40+
'system' => $facts['python3_version'],
41+
default => $version,
42+
}
43+
44+
# Debian splits the venv module into a seperate package
45+
if ( $facts['os']['family'] == 'Debian'){
46+
$python3_venv_package="python${python_version}-venv"
47+
case $facts['lsbdistcodename'] {
48+
'xenial','bionic','cosmic','disco',
49+
'jessie','stretch','buster': {
50+
ensure_packages ($python3_venv_package, {
51+
before => File[$venv_dir],
52+
})
53+
}
54+
default: {}
55+
}
56+
}
3957

40-
$virtualenv_cmd = $version ? {
41-
'system' => "${python::exec_prefix}pyvenv",
42-
default => "${python::exec_prefix}pyvenv-${version}",
58+
# pyvenv is deprecated since 3.6 and will be removed in 3.8
59+
if (versioncmp($facts['python3_version'], '3.6') >=0) {
60+
$virtualenv_cmd = "${python::exec_prefix}python${python_version} -m venv"
61+
} else {
62+
$virtualenv_cmd = "${python::exec_prefix}pyvenv-${python_version}"
4363
}
4464

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

spec/default_module_facts.yml

Lines changed: 3 additions & 0 deletions
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

Lines changed: 6 additions & 3 deletions
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)