Skip to content

Commit ff8df63

Browse files
Support Ubuntu 20.04 (#593)
add support for Ubuntu 20.04 Co-authored-by: Tim Meusel <[email protected]>
1 parent 7941a0c commit ff8df63

File tree

9 files changed

+51
-60
lines changed

9 files changed

+51
-60
lines changed

manifests/install.pp

+4-1
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,11 @@
284284
$pip_package = 'pip'
285285
$pip_provider = 'pip'
286286
} else {
287+
$pip_package = $facts['os']['release']['major'] ? {
288+
'20.04' => 'python3-pip',
289+
default => 'python-pip',
290+
}
287291
$pip_category = undef
288-
$pip_package = 'python-pip'
289292
$pip_provider = 'pip'
290293
}
291294

manifests/params.pp

+5-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
}
1111

1212
$ensure = 'present'
13-
$version = 'system'
1413
$pip = 'present'
1514
$dev = 'absent'
1615
$virtualenv = 'absent'
@@ -46,4 +45,9 @@
4645
'RedHat' => 'python-gunicorn',
4746
default => 'gunicorn',
4847
}
48+
49+
$version = $facts['os']['release']['major'] ? {
50+
'20.04' => '3',
51+
default => 'system',
52+
}
4953
}

manifests/pyvenv.pp

+2-8
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,9 @@
4646
# Debian splits the venv module into a seperate package
4747
if ( $facts['os']['family'] == 'Debian') {
4848
$python3_venv_package = "python${normalized_python_version}-venv"
49+
ensure_packages($python3_venv_package)
4950

50-
case $facts['os']['distro']['codename'] {
51-
'xenial', 'bionic', 'cosmic', 'disco', 'stretch', 'buster': {
52-
ensure_packages($python3_venv_package)
53-
54-
Package[$python3_venv_package] -> File[$venv_dir]
55-
}
56-
default: {}
57-
}
51+
Package[$python3_venv_package] -> File[$venv_dir]
5852
}
5953

6054
# pyvenv is deprecated since 3.6 and will be removed in 3.8

manifests/virtualenv.pp

+14-19
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
# @param systempkgs Copy system site-packages into virtualenv.
88
# @param venv_dir Directory to install virtualenv to
99
# @param ensure_venv_dir Create $venv_dir
10-
# @param distribute Include distribute in the virtualenv
10+
# @param distribute
11+
# Include distribute in the virtualenv
12+
# Forced to `false` for Ubuntu 18.04 and 20.04
13+
# Forced to `false` for RedHat based systems
1114
# @param index Base URL of Python package index
1215
# @param owner The owner of the virtualenv being manipulated
1316
# @param group The group relating to the virtualenv being manipulated
@@ -93,31 +96,23 @@
9396
}
9497
}
9598

96-
# Virtualenv versions prior to 1.7 do not support the
97-
# --system-site-packages flag, default off for prior versions
98-
# Prior to version 1.7 the default was equal to --system-site-packages
99-
# and the flag --no-site-packages had to be passed to do the opposite
100-
$_virtualenv_version = getvar('virtualenv_version') ? {
101-
/.*/ => getvar('virtualenv_version'),
99+
$system_pkgs_flag = $systempkgs ? {
100+
true => '--system-site-packages',
102101
default => '',
103102
}
104103

105-
if versioncmp($_virtualenv_version,'1.7') > 0 and $systempkgs == true {
106-
$system_pkgs_flag = '--system-site-packages'
107-
} elsif versioncmp($_virtualenv_version,'1.7') < 0 and $systempkgs == false {
108-
$system_pkgs_flag = '--no-site-packages'
104+
# Installing distribute does not work on these operating systems
105+
if $facts.dig('os','distro','codename') in ['focal', 'bionic', 'buster'] {
106+
$distribute_pkg = 'setuptools'
107+
} elsif $facts['os']['family'] == 'RedHat' {
108+
$distribute_pkg = 'setuptools'
109109
} else {
110-
$system_pkgs_flag = $systempkgs ? {
111-
true => '--system-site-packages',
112-
default => '--no-site-packages',
110+
$distribute_pkg = $distribute ? {
111+
true => 'distribute',
112+
default => 'setuptools',
113113
}
114114
}
115115

116-
$distribute_pkg = $distribute ? {
117-
true => 'distribute',
118-
default => 'setuptools',
119-
}
120-
121116
$pypi_index = $index ? {
122117
false => '',
123118
default => "-i ${index}",

metadata.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"operatingsystem": "Ubuntu",
4343
"operatingsystemrelease": [
4444
"16.04",
45-
"18.04"
45+
"18.04",
46+
"20.04"
4647
]
4748
},
4849
{

spec/acceptance/facts_test_spec.rb

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
context 'facts' do
55
install_python = <<-EOS
66
class { 'python' :
7-
version => 'system',
87
pip => 'present',
98
virtualenv => 'present',
109
}

spec/acceptance/virtualenv_spec.rb

+10-25
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ class { 'python' :
3232

3333
it 'maintains pip version' do
3434
pp = <<-EOS
35-
if $facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '16.04' {
36-
$version = '3'
37-
} else {
38-
$version = 'system'
39-
}
35+
$version = '3'
36+
4037
class { 'python' :
4138
version => $version,
4239
pip => 'present',
@@ -61,11 +58,8 @@ class { 'python' :
6158

6259
it 'works with ensure=>latest' do
6360
pp = <<-EOS
64-
if $facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '16.04' {
65-
$version = '3'
66-
} else {
67-
$version = 'system'
68-
}
61+
$version = '3'
62+
6963
class { 'python' :
7064
version => $version,
7165
pip => 'present',
@@ -92,11 +86,8 @@ class { 'python' :
9286

9387
it 'works with ensure=>latest for package with underscore in its name' do
9488
pp = <<-EOS
95-
if $facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '16.04' {
96-
$version = '3'
97-
} else {
98-
$version = 'system'
99-
}
89+
$version = '3'
90+
10091
class { 'python' :
10192
version => $version,
10293
pip => 'present',
@@ -123,11 +114,8 @@ class { 'python' :
123114

124115
it 'works with editable=>true' do
125116
pp = <<-EOS
126-
if $facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '16.04' {
127-
$version = '3'
128-
} else {
129-
$version = 'system'
130-
}
117+
$version = '3'
118+
131119
package{ 'git' :
132120
ensure => 'present',
133121
}
@@ -157,11 +145,8 @@ class { 'python' :
157145

158146
it 'works with == in pkgname' do
159147
pp = <<-EOS
160-
if $facts['os']['name'] == 'Ubuntu' and $facts['os']['release']['major'] == '16.04' {
161-
$version = '3'
162-
} else {
163-
$version = 'system'
164-
}
148+
$version = '3'
149+
165150
class { 'python' :
166151
version => $version,
167152
pip => 'present',

spec/defines/pip_spec.rb

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@
1010
kernel: 'Linux',
1111
lsbdistcodename: 'squeeze',
1212
os: {
13-
family: 'Debian'
13+
family: 'Debian',
14+
release: { major: '6' },
1415
},
1516
osfamily: 'Debian',
1617
operatingsystem: 'Debian',

spec/defines/virtualenv_spec.rb

+12-3
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,27 @@
1010
let :title do
1111
'/opt/env'
1212
end
13+
let(:distribute_pkg) do
14+
if facts[:os]['family'] == 'Debian' && %w[focal bionic buster].include?(facts[:os]['distro']['codename'])
15+
'setuptools'
16+
elsif facts[:os]['family'] == 'RedHat'
17+
'setuptools'
18+
else
19+
'distribute'
20+
end
21+
end
1322

1423
context 'with default parameters' do
1524
it { is_expected.to compile.with_all_deps }
1625
it { is_expected.to contain_file('/opt/env') }
17-
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command('virtualenv --no-site-packages -p python /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --proxy= --upgrade pip && /opt/env/bin/pip install --proxy= --upgrade distribute') }
26+
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command("virtualenv -p python /opt/env && /opt/env/bin/pip --log /opt/env/pip.log install --proxy= --upgrade pip && /opt/env/bin/pip install --proxy= --upgrade #{distribute_pkg}") }
1827
end
1928

2029
context 'when virtualenv is defined' do
21-
let(:params) {{ virtualenv: 'virtualenv-3' }}
30+
let(:params) { { virtualenv: 'virtualenv-3' } }
2231

2332
it { is_expected.to compile.with_all_deps }
24-
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command(%r{virtualenv-3 --no-site-packages -p python .+}) }
33+
it { is_expected.to contain_exec('python_virtualenv_/opt/env').with_command(%r{virtualenv-3 -p python .+}) }
2534
end
2635

2736
describe 'when ensure' do

0 commit comments

Comments
 (0)