Skip to content

Commit

Permalink
Merge pull request #460 from feltra/add_pip_bootstrap
Browse files Browse the repository at this point in the history
move pip bootstrap into a seperate class
  • Loading branch information
bastelfreak authored Jan 14, 2019
2 parents 118135c + 431d297 commit c7ab354
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 14 deletions.
15 changes: 1 addition & 14 deletions manifests/install.pp
Original file line number Diff line number Diff line change
Expand Up @@ -72,20 +72,7 @@
}

# Install pip without pip, see https://pip.pypa.io/en/stable/installing/.
exec { 'bootstrap pip':
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
unless => 'which pip',
path => [ '/bin', '/usr/bin', '/usr/local/bin' ],
require => Package['python'],
}

# Puppet is opinionated about the pip command name
file { 'pip-python':
ensure => link,
path => '/usr/bin/pip-python',
target => '/usr/bin/pip',
require => Exec['bootstrap pip'],
}
include 'python::pip::bootstrap'

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

Expand Down
5 changes: 5 additions & 0 deletions manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@
$use_epel = false
}

$pip_lookup_path = $facts['os']['family'] ? {
'AIX' => [ '/bin', '/usr/bin', '/usr/local/bin', '/opt/freeware/bin/' ],
default => [ '/bin', '/usr/bin', '/usr/local/bin' ]
}

$gunicorn_package_name = $::osfamily ? {
'RedHat' => 'python-gunicorn',
default => 'gunicorn',
Expand Down
52 changes: 52 additions & 0 deletions manifests/pip/bootstrap.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#
# @summary allow to bootstrap pip when python is managed from other module
#
# @param version should be pip or pip3
# @param manage_python if python module will manage deps
#
# @example
# class { 'python::pip::bootstrap':
# version => 'pip',
# }
class python::pip::bootstrap (
Enum['pip', 'pip3'] $version = 'pip',
Variant[Boolean, String] $manage_python = false,
) inherits ::python::params {
if $manage_python {
include ::python
} else {
$target_src_pip_path = $facts['os']['family'] ? {
'AIX' => '/opt/freeware/bin',
default => '/usr/bin'
}
if $version == 'pip3' {
exec { 'bootstrap pip3':
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python3',
unless => 'which pip3',
path => $python::params::pip_lookup_path,
require => Package['python3'],
}
# puppet is opinionated about the pip command name
file { 'pip3-python':
ensure => link,
path => '/usr/bin/pip3',
target => "${target_src_pip_path}/pip${::facts['python3_release']}",
require => Exec['bootstrap pip3'],
}
} else {
exec { 'bootstrap pip':
command => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python',
unless => 'which pip',
path => $python::params::pip_lookup_path,
require => Package['python'],
}
# puppet is opinionated about the pip command name
file { 'pip-python':
ensure => link,
path => '/usr/bin/pip',
target => "${target_src_pip_path}/pip${::facts['python2_release']}",
require => Exec['bootstrap pip'],
}
}
}
}

0 comments on commit c7ab354

Please sign in to comment.