Skip to content

Commit 2e94933

Browse files
authored
Merge pull request #414 from paychex/pip3-support
support for providing pip3 provider w/ tests. Modified readme 4 examples
2 parents b5c6798 + c86dd5d commit 2e94933

4 files changed

Lines changed: 91 additions & 36 deletions

File tree

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic
5757

5858
**use_epel** - Boolean to determine if the epel class is used. Default: true on RHEL like systems, false otherwise
5959

60+
*Install Python from system python*
6061
```puppet
6162
class { 'python' :
6263
version => 'system',
@@ -66,6 +67,15 @@ Installs and manages python, python-pip, python-dev, python-virtualenv and Gunic
6667
gunicorn => 'absent',
6768
}
6869
```
70+
*Install Python 3 from the scl repo*
71+
```puppet
72+
class { 'python' :
73+
ensure => 'present',
74+
version => 'rh-python36-python',
75+
dev => 'present',
76+
virtualenv => 'present',
77+
}
78+
```
6979

7080
### python::pip
7181

@@ -77,6 +87,8 @@ Installs and manages packages from pip.
7787

7888
**virtualenv** - virtualenv to run pip in. Default: system (no virtualenv)
7989

90+
**pip_provider** - pip provider to execute pip with. Default: pip.
91+
8092
**url** - URL to install from. Default: none
8193

8294
**owner** - The owner of the virtualenv to ensure that packages are installed with the correct permissions (must be specified). Default: root
@@ -94,6 +106,8 @@ Installs and manages packages from pip.
94106
**uninstall_args** - String of additional flags to pass to pip during uninstall. Default: none
95107

96108
**timeout** - Timeout for the pip install command. Defaults to 1800.
109+
110+
*Install cx_Oracle with pip*
97111
```puppet
98112
python::pip { 'cx_Oracle' :
99113
pkgname => 'cx_Oracle',
@@ -106,6 +120,17 @@ Installs and manages packages from pip.
106120
timeout => 1800,
107121
}
108122
```
123+
*Install Requests with pip3*
124+
```puppet
125+
python::pip { 'requests' :
126+
ensure => 'present',
127+
pkgname => 'requests',
128+
pip_provider => 'pip3',
129+
virtualenv => '/var/www/project1',
130+
owner => 'root',
131+
timeout => 1800
132+
}
133+
```
109134

110135
### python::requirements
111136

manifests/pip.pp

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@
1616
# [*virtualenv*]
1717
# virtualenv to run pip in.
1818
#
19+
# [*pip_provider*]
20+
# version of pip you wish to use. Default: pip
21+
#
1922
# [*url*]
2023
# URL to install from. Default: none
2124
#
@@ -66,26 +69,28 @@
6669
#
6770
# Sergey Stankevich
6871
# Fotis Gimian
72+
# Daniel Quackenbush
6973
#
7074
define python::pip (
71-
$pkgname = $name,
72-
$ensure = present,
73-
$virtualenv = 'system',
74-
$url = false,
75-
$owner = 'root',
76-
$group = 'root',
77-
$umask = undef,
78-
$index = false,
79-
$proxy = false,
80-
$egg = false,
81-
$editable = false,
82-
$environment = [],
83-
$extras = [],
84-
$install_args = '',
85-
$uninstall_args = '',
86-
$timeout = 1800,
87-
$log_dir = '/tmp',
88-
$path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
75+
$pkgname = $name,
76+
$ensure = present,
77+
$virtualenv = 'system',
78+
Enum['pip', 'pip3'] $pip_provider = 'pip',
79+
$url = false,
80+
$owner = 'root',
81+
$group = 'root',
82+
$umask = undef,
83+
$index = false,
84+
$proxy = false,
85+
$egg = false,
86+
$editable = false,
87+
$environment = [],
88+
$extras = [],
89+
$install_args = '',
90+
$uninstall_args = '',
91+
$timeout = 1800,
92+
$log_dir = '/tmp',
93+
$path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
8994
) {
9095
$python_provider = getparam(Class['python'], 'provider')
9196
$python_version = getparam(Class['python'], 'version')
@@ -125,8 +130,8 @@
125130
}
126131

127132
$pip_env = $virtualenv ? {
128-
'system' => "${exec_prefix}pip",
129-
default => "${exec_prefix}${virtualenv}/bin/pip",
133+
'system' => "${exec_prefix}${pip_provider}",
134+
default => "${exec_prefix}${virtualenv}/bin/${pip_provider}",
130135
}
131136

132137
$pypi_index = $index ? {

manifests/requirements.pp

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
# [*virtualenv*]
1111
# virtualenv to run pip in. Default: system-wide
1212
#
13+
# [*pip_provider*]
14+
# version of pip you wish to use. Default: pip
15+
#
1316
# [*owner*]
1417
# The owner of the virtualenv being manipulated. Default: root
1518
#
@@ -62,22 +65,24 @@
6265
# Sergey Stankevich
6366
# Ashley Penney
6467
# Fotis Gimian
68+
# Daniel Quackenbush
6569
#
6670
define python::requirements (
67-
$requirements = $name,
68-
$virtualenv = 'system',
69-
$owner = 'root',
70-
$group = 'root',
71-
$proxy = false,
72-
$src = false,
73-
$environment = [],
74-
$forceupdate = false,
75-
$cwd = undef,
76-
$extra_pip_args = '',
77-
$manage_requirements = true,
78-
$fix_requirements_owner = true,
79-
$log_dir = '/tmp',
80-
$timeout = 1800,
71+
$requirements = $name,
72+
$virtualenv = 'system',
73+
Enum['pip', 'pip3'] $pip_provider = 'pip',
74+
$owner = 'root',
75+
$group = 'root',
76+
$proxy = false,
77+
$src = false,
78+
$environment = [],
79+
$forceupdate = false,
80+
$cwd = undef,
81+
$extra_pip_args = '',
82+
$manage_requirements = true,
83+
$fix_requirements_owner = true,
84+
$log_dir = '/tmp',
85+
$timeout = 1800,
8186
) {
8287

8388
include ::python
@@ -100,8 +105,8 @@
100105
}
101106

102107
$pip_env = $virtualenv ? {
103-
'system' => "${::python::exec_prefix} pip",
104-
default => "${::python::exec_prefix} ${virtualenv}/bin/pip",
108+
'system' => "${::python::exec_prefix} ${pip_provider}",
109+
default => "${::python::exec_prefix} ${virtualenv}/bin/${pip_provider}",
105110
}
106111

107112
$proxy_flag = $proxy ? {

spec/defines/pip_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,26 @@
3838
end
3939
end
4040

41+
describe 'pip_provide as' do
42+
context 'defaults to pip' do
43+
let(:params) { {} }
44+
45+
it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip}) }
46+
it { is_expected.not_to contain_exec('pip_install_rpyc').with_command(%r{pip3}) }
47+
end
48+
context 'use pip instead of pip3 when specified' do
49+
let(:params) { { pip_provider: 'pip' } }
50+
51+
it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip}) }
52+
it { is_expected.not_to contain_exec('pip_install_rpyc').with_command(%r{pip3}) }
53+
end
54+
context 'use pip3 instead of pip when specified' do
55+
let(:params) { { pip_provider: 'pip3' } }
56+
57+
it { is_expected.to contain_exec('pip_install_rpyc').with_command(%r{pip3}) }
58+
end
59+
end
60+
4161
describe 'proxy as' do
4262
context 'defaults to empty' do
4363
let(:params) { {} }

0 commit comments

Comments
 (0)