Skip to content

Commit c7ab354

Browse files
authored
Merge pull request #460 from feltra/add_pip_bootstrap
move pip bootstrap into a seperate class
2 parents 118135c + 431d297 commit c7ab354

File tree

3 files changed

+58
-14
lines changed

3 files changed

+58
-14
lines changed

manifests/install.pp

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,20 +72,7 @@
7272
}
7373

7474
# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
75-
exec { 'bootstrap pip':
76-
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
77-
unless => 'which pip',
78-
path => [ '/bin', '/usr/bin', '/usr/local/bin' ],
79-
require => Package['python'],
80-
}
81-
82-
# Puppet is opinionated about the pip command name
83-
file { 'pip-python':
84-
ensure => link,
85-
path => '/usr/bin/pip-python',
86-
target => '/usr/bin/pip',
87-
require => Exec['bootstrap pip'],
88-
}
75+
include 'python::pip::bootstrap'
8976

9077
Exec['bootstrap pip'] -> File['pip-python'] -> Package <| provider == pip |>
9178

manifests/params.pp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,11 @@
2727
$use_epel = false
2828
}
2929

30+
$pip_lookup_path = $facts['os']['family'] ? {
31+
'AIX' => [ '/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/' ],
32+
default => [ '/bin', '/usr/bin', '/usr/local/bin' ]
33+
}
34+
3035
$gunicorn_package_name = $::osfamily ? {
3136
'RedHat' => 'python-gunicorn',
3237
default => 'gunicorn',

manifests/pip/bootstrap.pp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
#
2+
# @summary allow to bootstrap pip when python is managed from other module
3+
#
4+
# @param version should be pip or pip3
5+
# @param manage_python if python module will manage deps
6+
#
7+
# @example
8+
# class { 'python::pip::bootstrap':
9+
# version => 'pip',
10+
# }
11+
class python::pip::bootstrap (
12+
Enum['pip', 'pip3'] $version = 'pip',
13+
Variant[Boolean, String] $manage_python = false,
14+
) inherits ::python::params {
15+
if $manage_python {
16+
include ::python
17+
} else {
18+
$target_src_pip_path = $facts['os']['family'] ? {
19+
'AIX' => '/opt/freeware/bin',
20+
default => '/usr/bin'
21+
}
22+
if $version == 'pip3' {
23+
exec { 'bootstrap pip3':
24+
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python3',
25+
unless => 'which pip3',
26+
path => $python::params::pip_lookup_path,
27+
require => Package['python3'],
28+
}
29+
# puppet is opinionated about the pip command name
30+
file { 'pip3-python':
31+
ensure => link,
32+
path => '/usr/bin/pip3',
33+
target => "${target_src_pip_path}/pip${::facts['python3_release']}",
34+
require => Exec['bootstrap pip3'],
35+
}
36+
} else {
37+
exec { 'bootstrap pip':
38+
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
39+
unless => 'which pip',
40+
path => $python::params::pip_lookup_path,
41+
require => Package['python'],
42+
}
43+
# puppet is opinionated about the pip command name
44+
file { 'pip-python':
45+
ensure => link,
46+
path => '/usr/bin/pip',
47+
target => "${target_src_pip_path}/pip${::facts['python2_release']}",
48+
require => Exec['bootstrap pip'],
49+
}
50+
}
51+
}
52+
}

0 commit comments

Comments
 (0)