annotate modules/python/manifests/pip.pp @ 482:d83de9b3a62b default tip

Update hiera.yaml within Puppet config Forgot that we manage it from here. Now has content to match new packages
author IBBoard <dev@ibboard.co.uk>
date Fri, 30 Aug 2024 16:10:36 +0100
parents adf6fe9bbc17
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
1 # @summary Installs and manages packages from pip.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
2 #
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
3 # @param name must be unique
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
4 # @param pkgname the name of the package.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
5 # @param ensure Require pip to be available.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
6 # @param virtualenv virtualenv to run pip in.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
7 # @param pip_provider version of pip you wish to use.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
8 # @param url URL to install from.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
9 # @param owner The owner of the virtualenv being manipulated.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
10 # @param group The group of the virtualenv being manipulated.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
11 # @param index Base URL of Python package index.
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
12 # @param extra_index Base URL of extra Python package index.
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
13 # @param proxy Proxy server to use for outbound connections.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
14 # @param editable If true the package is installed as an editable resource.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
15 # @param environment Additional environment variables required to install the packages.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
16 # @param extras Extra features provided by the package which should be installed.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
17 # @param timeout The maximum time in seconds the "pip install" command should take.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
18 # @param install_args Any additional installation arguments that will be supplied when running pip install.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
19 # @param uninstall_args Any additional arguments that will be supplied when running pip uninstall.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
20 # @param log_dir Log directory
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
21 # @param egg The egg name to use
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
22 # @param umask
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
23 #
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
24 # @example Install Flask to /var/www/project1 using a proxy
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
25 # python::pip { 'flask':
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
26 # virtualenv => '/var/www/project1',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
27 # proxy => 'http://proxy.domain.com:3128',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
28 # index => 'http://www.example.com/simple/',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
29 # }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
30 # @example Install cx_Oracle with pip
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
31 # python::pip { 'cx_Oracle' :
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
32 # pkgname => 'cx_Oracle',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
33 # ensure => '5.1.2',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
34 # virtualenv => '/var/www/project1',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
35 # owner => 'appuser',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
36 # proxy => 'http://proxy.domain.com:3128',
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
37 # environment => ['ORACLE_HOME=/usr/lib/oracle/11.2/client64'],
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
38 # install_args => '-e',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
39 # timeout => 1800,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
40 # }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
41 # @example Install Requests with pip3
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
42 # python::pip { 'requests' :
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
43 # ensure => 'present',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
44 # pkgname => 'requests',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
45 # pip_provider => 'pip3',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
46 # virtualenv => '/var/www/project1',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
47 # owner => 'root',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
48 # timeout => 1800
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
49 # }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
50 #
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
51 define python::pip (
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
52 String[1] $pkgname = $name,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
53 Variant[Enum[present, absent, latest], String[1]] $ensure = present,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
54 Variant[Enum['system'], Stdlib::Absolutepath] $virtualenv = 'system',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
55 String[1] $pip_provider = 'pip',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
56 Variant[Boolean, String] $url = false,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
57 String[1] $owner = 'root',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
58 Optional[String[1]] $group = getvar('python::params::group'),
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
59 Optional[Python::Umask] $umask = undef,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
60 Variant[Boolean,String[1]] $index = false,
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
61 Variant[Boolean,String[1]] $extra_index = false,
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
62 Optional[Stdlib::HTTPUrl] $proxy = undef,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
63 Any $egg = false,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
64 Boolean $editable = false,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
65 Array $environment = [],
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
66 Array $extras = [],
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
67 Optional[String[1]] $install_args = undef,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
68 Optional[String[1]] $uninstall_args = undef,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
69 Numeric $timeout = 1800,
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
70 String[1] $log_dir = '/tmp',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
71 Array[String] $path = ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
72 String[1] $exec_provider = 'shell',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
73 ) {
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
74 $python_provider = getparam(Class['python'], 'provider')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
75 $python_version = getparam(Class['python'], 'version')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
76
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
77 if $virtualenv != 'system' {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
78 Python::Pyvenv <| |> -> Python::Pip[$name]
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
79 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
80
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
81 # Get SCL exec prefix
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
82 # NB: this will not work if you are running puppet from scl enabled shell
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
83 $exec_prefix = $python_provider ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
84 'scl' => "scl enable ${python_version} -- ",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
85 'rhscl' => "scl enable ${python_version} -- ",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
86 default => '',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
87 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
88
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
89 $_path = $python_provider ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
90 'anaconda' => concat(["${python::anaconda_install_path}/bin"], $path),
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
91 default => $path,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
92 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
93
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
94 # Parameter validation
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
95 if $virtualenv == 'system' and $owner != 'root' {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
96 fail('python::pip: root user must be used when virtualenv is system')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
97 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
98
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
99 $cwd = $virtualenv ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
100 'system' => '/',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
101 default => $virtualenv,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
102 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
103
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
104 $log = $virtualenv ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
105 'system' => $log_dir,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
106 default => $virtualenv,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
107 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
108
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
109 $pip_env = $virtualenv ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
110 'system' => "${exec_prefix}${pip_provider}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
111 default => "${exec_prefix}${virtualenv}/bin/${pip_provider}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
112 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
113
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
114 $pypi_index = $index ? {
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
115 false => '',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
116 default => "--index-url=${index}",
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
117 }
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
118
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
119 $pypi_extra_index = $extra_index ? {
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
120 false => '',
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
121 default => "--extra-index-url=${extra_index}",
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
122 }
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
123
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
124 $proxy_flag = $proxy ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
125 undef => '',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
126 default => "--proxy=${proxy}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
127 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
128
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
129 if $editable == true {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
130 $install_editable = ' -e '
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
131 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
132 else {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
133 $install_editable = ''
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
134 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
135
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
136 # TODO: Do more robust argument checking, but below is a start
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
137 if ($ensure == absent) and $install_args {
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
138 fail('python::pip cannot provide install_args with ensure => absent')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
139 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
140
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
141 if ($ensure == present) and $uninstall_args {
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
142 fail('python::pip cannot provide uninstall_args with ensure => present')
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
143 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
144
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
145 if $pkgname =~ /==/ {
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
146 $parts = split($pkgname, '==')
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
147 $real_pkgname = $parts[0]
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
148
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
149 $_ensure = $ensure ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
150 'absent' => 'absent',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
151 default => $parts[1],
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
152 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
153 } else {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
154 $real_pkgname = $pkgname
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
155 $_ensure = $ensure
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
156 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
157
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
158 # Check if searching by explicit version.
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
159 if $_ensure =~ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/ {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
160 $grep_regex = "^${real_pkgname}[[:space:]]\\+(\\?${_ensure}\\()$\\|$\\|, \\|[[:space:]]\\)"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
161 } else {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
162 $grep_regex = "^${real_pkgname}[[:space:]].*$"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
163 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
164
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
165 $extras_string = empty($extras) ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
166 true => '',
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
167 default => sprintf('[%s]',join($extras,',')),
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
168 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
169
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
170 $egg_name = $egg ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
171 false => "${real_pkgname}${extras_string}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
172 default => $egg
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
173 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
174
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
175 $source = $url ? {
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
176 false => "${real_pkgname}${extras_string}",
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
177 /^(\/|[a-zA-Z]\:)/ => "'${url}'",
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
178 /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ => "'${url}'",
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
179 default => "'${url}#egg=${egg_name}'",
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
180 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
181
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
182 $pip_install = "${pip_env} --log ${log}/pip.log install"
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
183 $pip_common_args = "${pypi_index} ${pypi_extra_index} ${proxy_flag} ${install_editable} ${source}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
184
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
185 # Explicit version out of VCS when PIP supported URL is provided
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
186 if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
187 if $_ensure != present and $_ensure != latest {
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
188 $command = "${pip_install} ${install_args} ${pip_common_args}@${_ensure}#egg=${egg_name}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
189 $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
190 } else {
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
191 $command = "${pip_install} ${install_args} ${pip_common_args}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
192 $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
193 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
194 } else {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
195 case $_ensure {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
196 /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/: {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
197 # Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
198 # Explicit version.
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
199 $command = "${pip_install} ${install_args} ${pip_common_args}==${_ensure}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
200 $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
201 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
202
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
203 'present': {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
204 # Whatever version is available.
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
205 $command = "${pip_install} ${install_args} ${pip_common_args}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
206 $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
207 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
208
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
209 'latest': {
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
210 $pip_version = $facts['pip_version']
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
211 if $pip_version and versioncmp($pip_version, '21.1') == -1 and versioncmp($pip_version, '20.2.4') == 1 {
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
212 $legacy_resolver = '--use-deprecated=legacy-resolver'
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
213 } else {
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
214 $legacy_resolver = ''
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
215 }
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
216
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
217 # Unfortunately this is the smartest way of getting the latest available package version with pip as of now
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
218 # Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
219 # more than one line with paretheses.
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
220 $latest_version = join([
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
221 "${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}",
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
222 " ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1",
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
223 " | sed -nE 's/.*\\(from versions: (.*, )*(.*)\\)/\\2/p'",
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
224 ' | tr -d "[:space:]"',
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
225 ])
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
226
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
227 # Packages with underscores in their names are listed with dashes in their place in `pip freeze` output
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
228 $pkgname_with_dashes = regsubst($real_pkgname, '_', '-', 'G')
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
229 $grep_regex_pkgname_with_dashes = "^${pkgname_with_dashes}=="
478
adf6fe9bbc17 Update Puppet modules to latest versions
IBBoard <dev@ibboard.co.uk>
parents: 387
diff changeset
230 $installed_version = join(["${pip_env} freeze --all", " | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3", " | tr -d '[:space:]'",])
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
231
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
232 $command = "${pip_install} --upgrade ${install_args} ${pip_common_args}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
233 $unless_command = "[ \$(${latest_version}) = \$(${installed_version}) ]"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
234 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
235
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
236 default: {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
237 # Anti-action, uninstall.
387
66c075c5f54a Update to newer Python module
IBBoard <dev@ibboard.co.uk>
parents: 272
diff changeset
238 $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${real_pkgname}"
272
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
239 $unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'"
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
240 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
241 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
242 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
243
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
244 $pip_installer = ($ensure == 'absent') ? {
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
245 true => "pip_uninstall_${name}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
246 false => "pip_install_${name}",
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
247 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
248
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
249 exec { $pip_installer:
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
250 command => $command,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
251 unless => $unless_command,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
252 user => $owner,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
253 group => $group,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
254 umask => $umask,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
255 cwd => $cwd,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
256 environment => $environment,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
257 timeout => $timeout,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
258 path => $_path,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
259 provider => $exec_provider,
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
260 }
c42fb28cff86 Update to a newer Python module
IBBoard <dev@ibboard.co.uk>
parents:
diff changeset
261 }