Skip to content

Commit 66c1b78

Browse files
committed
Install pip packages in python::install::pip
1 parent 078c8a3 commit 66c1b78

File tree

5 files changed

+80
-30
lines changed

5 files changed

+80
-30
lines changed

REFERENCE.md

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

1111
* [`python`](#python): Installs and manages python, python-dev and gunicorn.
1212
* [`python::install::dev`](#python--install--dev): Installs python development packages
13+
* [`python::install::pip`](#python--install--pip): Installs python pip packages
1314
* [`python::install::venv`](#python--install--venv): Installs python virtualenv packages
1415
* [`python::pip::bootstrap`](#python--pip--bootstrap): allow to bootstrap pip when python is managed from other module
1516

@@ -295,6 +296,10 @@ Default value: `'/opt/python'`
295296

296297
Installs python development packages
297298

299+
### <a name="python--install--pip"></a>`python::install::pip`
300+
301+
Installs python pip packages
302+
298303
### <a name="python--install--venv"></a>`python::install::venv`
299304

300305
Installs python virtualenv packages

manifests/install.pp

+3-13
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,7 @@
3838
case $python::provider {
3939
'pip': {
4040
if $python::manage_pip_package {
41-
package { 'pip':
42-
ensure => $python::pip,
43-
require => Package['python'],
44-
}
41+
contain python::install::pip
4542
}
4643

4744
if $python::manage_dev_package and $pythondev {
@@ -159,11 +156,7 @@
159156
}
160157
} else {
161158
if $python::manage_pip_package {
162-
package { 'python-pip':
163-
ensure => $python::pip,
164-
require => Package['python'],
165-
provider => 'yum',
166-
}
159+
contain python::install::pip
167160
}
168161
}
169162

@@ -173,10 +166,7 @@
173166
}
174167
default: {
175168
if $python::manage_pip_package {
176-
package { 'pip':
177-
ensure => $python::pip,
178-
require => Package['python'],
179-
}
169+
contain python::install::pip
180170
}
181171

182172
if $python::manage_dev_package and $pythondev {

manifests/install/pip.pp

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# @summary Installs python pip packages
2+
class python::install::pip {
3+
include python
4+
5+
case $python::provider {
6+
'pip': {
7+
package { 'pip':
8+
ensure => $python::pip,
9+
require => Package['python'],
10+
}
11+
}
12+
'scl': {
13+
}
14+
'rhscl': {
15+
}
16+
'anaconda': {
17+
}
18+
default: {
19+
case $facts['os']['family'] {
20+
'AIX': {
21+
unless String($python::version) =~ /^python3/ {
22+
package { 'python-pip':
23+
ensure => $python::pip,
24+
require => Package['python'],
25+
provider => 'yum',
26+
}
27+
}
28+
}
29+
default: {
30+
package { 'pip':
31+
ensure => $python::pip,
32+
require => Package['python'],
33+
}
34+
}
35+
}
36+
}
37+
}
38+
}

spec/classes/install/pip_spec.rb

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'python::install::pip' do
6+
on_supported_os.each do |os, facts|
7+
context "on #{os}" do
8+
let :facts do
9+
facts
10+
end
11+
12+
context 'with default settings' do
13+
it { is_expected.to contain_package('pip').with(ensure: 'present') }
14+
end
15+
16+
context 'when ensuring pip is absent' do
17+
let(:pre_condition) do
18+
<<~PP
19+
class { 'python':
20+
pip => absent,
21+
}
22+
PP
23+
end
24+
25+
it { is_expected.to contain_package('pip').with(ensure: 'absent') }
26+
end
27+
end
28+
end
29+
end

spec/classes/python_spec.rb

+5-17
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@
1717
it { is_expected.to contain_class('python::config') }
1818
it { is_expected.to contain_package('python') }
1919

20-
if facts[:os]['family'] == 'Archlinux'
21-
it { is_expected.not_to contain_package('pip') }
20+
if %w[Archlinux].include?(facts[:os]['family'])
21+
it { is_expected.not_to contain_class('python::install::pip') }
2222
else
23-
it { is_expected.to contain_package('pip') }
23+
it { is_expected.to contain_class('python::install::pip') }
2424
end
2525

2626
if %w[Archlinux FreeBSD RedHat].include?(facts[:os]['family'])
@@ -43,22 +43,10 @@
4343
it { is_expected.to compile.with_all_deps }
4444
it { is_expected.not_to contain_package('python') }
4545
it { is_expected.not_to contain_package('python-dev') }
46-
it { is_expected.not_to contain_package('pip') }
46+
it { is_expected.not_to contain_class('python::install::pip') }
4747
it { is_expected.not_to contain_class('python::install::venv') }
4848
end
4949

50-
context 'with packages present' do
51-
let :params do
52-
{
53-
manage_pip_package: true,
54-
pip: 'present',
55-
}
56-
end
57-
58-
it { is_expected.to compile.with_all_deps }
59-
it { is_expected.to contain_package('pip').with(ensure: 'present') }
60-
end
61-
6250
case facts[:os]['family']
6351
when 'Debian'
6452

@@ -68,7 +56,7 @@
6856
# Base debian packages.
6957
it { is_expected.to contain_package('python') }
7058
it { is_expected.to contain_package('python-dev') }
71-
it { is_expected.to contain_package('pip') }
59+
it { is_expected.to contain_class('python::install::pip') }
7260

7361
describe 'with python::version' do
7462
context 'python3.7' do

0 commit comments

Comments
 (0)