Puppet Class: python::pip::bootstrap

Inherits:
python::params
Defined in:
manifests/pip/bootstrap.pp

Summary

allow to bootstrap pip when python is managed from other module

Overview

Examples:

class { 'python::pip::bootstrap':
  version => 'pip',
}

Parameters:

  • version (Enum['pip', 'pip3']) (defaults to: 'pip')

    should be pip or pip3

  • manage_python (Variant[Boolean, String]) (defaults to: false)

    if python module will manage deps

  • http_proxy (Optional[Stdlib::HTTPUrl]) (defaults to: undef)

    Proxy server to use for outbound connections.

  • exec_provider (String[1]) (defaults to: 'shell')


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# File 'manifests/pip/bootstrap.pp', line 12

class python::pip::bootstrap (
  Enum['pip', 'pip3']       $version       = 'pip',
  Variant[Boolean, String]  $manage_python = false,
  Optional[Stdlib::HTTPUrl] $http_proxy    = undef,
  String[1]                 $exec_provider = 'shell',
) inherits python::params {
  if $manage_python {
    include python
  } else {
    $target_src_pip_path = $facts['os']['family'] ? {
      'AIX' => '/opt/freeware/bin',
      default => '/usr/bin'
    }

    $environ = $http_proxy ? {
      undef   => [],
      default => $facts['os']['family'] ? {
        'AIX'   => ["http_proxy=${http_proxy}", "https_proxy=${http_proxy}"],
        default => ["HTTP_PROXY=${http_proxy}", "HTTPS_PROXY=${http_proxy}"],
      }
    }

    if $version == 'pip3' {
      exec { 'bootstrap pip3':
        command     => '/usr/bin/curl https://bootstrap.pypa.io/get-pip.py | python3',
        environment => $environ,
        unless      => 'which pip3',
        path        => $python::params::pip_lookup_path,
        require     => Package['python3'],
        provider    => $exec_provider,
      }

      # 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',
        environment => $environ,
        unless      => 'which pip',
        path        => $python::params::pip_lookup_path,
        require     => Package['python'],
        provider    => $exec_provider,
      }

      # 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'],
      }
    }
  }
}