Defined Type: python::version

Defined in:
manifests/version.pp

Overview

Parameters:

  • ensure (Any) (defaults to: 'installed')
  • env (Any) (defaults to: {})
  • version (Any) (defaults to: $name)


8
9
10
11
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'manifests/version.pp', line 8

define python::version(
  $ensure  = 'installed',
  $env     = {},
  $version = $name,
) {
  require python

  $alias_hash = $python::version_alias
  $dest = "/opt/python/${version}"

  if has_key($alias_hash, $version) {
    $to = $alias_hash[$version]

    python::alias { $version:
      ensure => $ensure,
      to     => $to,
    }
  } elsif $ensure == 'absent' {
    file { $dest:
      ensure => absent,
      force  => true,
    }
  } else {
    case $version {
      /jython/: { require java }
      default: { }
    }

    $pyenv = $python::pyenv::prefix

    $default_env = {
      'CC'         => '/usr/bin/cc',
      'PYENV_ROOT' => $pyenv,
    }

    if $::operatingsystem == 'Darwin' {
      include homebrew::config
      include boxen::config
      ensure_resource('package', 'readline')
    }

    $env_data = $python::version_env

    if has_key($env_data, 'global') {
      $global_env = $env_data['global']
    } else {
      $global_env = {}
    }

    if has_key($env_data, $::operatingsystem) {
      $os_env = $env_data[$::operatingsystem]
    } else {
      $os_env = {}
    }

    if has_key($env_data, $version) {
      $version_env = $env_data[$version]
    } else {
      $version_env = {}
    }

    $_env = merge(
      merge(
        merge(
          merge($default_env, $os_env),
          $version_env
        ),
        $global_env,
      ),
      $env
    )

    if has_key($_env, 'CC') and $_env['CC'] =~ /gcc/ {
      require gcc
    }

    exec { "python-install-${version}":
      command  => "${pyenv}/bin/pyenv install --skip-existing ${version}",
      cwd      => "${pyenv}/versions",
      provider => 'shell',
      timeout  => 0,
      creates  => $dest,
      user     => $python::pyenv::user,
      require  => Package['readline'],
    }

    Exec["python-install-${version}"] {
      environment +> sort(join_keys_to_values($_env, '='))
    }
  }
}