|
135 | 135 | fail('python::pip cannot provide uninstall_args with ensure => present') |
136 | 136 | } |
137 | 137 |
|
| 138 | + if $pkgname =~ /==/ { |
| 139 | + $parts = split($pkgname, '==') |
| 140 | + $real_pkgname = $parts[0] |
| 141 | + $_ensure = $ensure ? { |
| 142 | + 'absent' => 'absent', |
| 143 | + default => $parts[1], |
| 144 | + } |
| 145 | + } else { |
| 146 | + $real_pkgname = $pkgname |
| 147 | + $_ensure = $ensure |
| 148 | + } |
| 149 | + |
138 | 150 | # Check if searching by explicit version. |
139 | | - 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+)*)$/ { |
140 | | - $grep_regex = "^${pkgname}==${ensure}\$" |
| 151 | + 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+)*)$/ { |
| 152 | + $grep_regex = "^${real_pkgname}[[:space:]]\\+(\\?${_ensure}\\()$\\|$\\|, \\|[[:space:]]\\)" |
141 | 153 | } else { |
142 | | - $grep_regex = $pkgname ? { |
143 | | - /==/ => "^${pkgname}\$", |
144 | | - default => "^${pkgname}==", |
145 | | - } |
| 154 | + $grep_regex = "^${real_pkgname}[[:space:]].*$" |
146 | 155 | } |
147 | 156 |
|
148 | 157 | $extras_string = empty($extras) ? { |
|
151 | 160 | } |
152 | 161 |
|
153 | 162 | $egg_name = $egg ? { |
154 | | - false => "${pkgname}${extras_string}", |
| 163 | + false => "${real_pkgname}${extras_string}", |
155 | 164 | default => $egg |
156 | 165 | } |
157 | 166 |
|
158 | 167 | $source = $url ? { |
159 | | - false => "${pkgname}${extras_string}", |
| 168 | + false => "${real_pkgname}${extras_string}", |
160 | 169 | /^(\/|[a-zA-Z]\:)/ => "'${url}'", |
161 | 170 | /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+$/ => "'${url}'", |
162 | 171 | default => "'${url}#egg=${egg_name}'", |
|
165 | 174 | $pip_install = "${pip_env} --log ${log}/pip.log install" |
166 | 175 | $pip_common_args = "${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}" |
167 | 176 |
|
| 177 | + $pip_exec_name = "pip_install_${name}" |
| 178 | + |
168 | 179 | # Explicit version out of VCS when PIP supported URL is provided |
169 | 180 | if $source =~ /^'(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp|git)(:\/\/).+'$/ { |
170 | | - if $ensure != present and $ensure != latest { |
171 | | - exec { "pip_install_${name}": |
172 | | - command => "${pip_install} ${install_args} ${pip_common_args}@${ensure}#egg=${egg_name}", |
173 | | - unless => "${pip_env} freeze --all | grep -i -e ${grep_regex}", |
174 | | - user => $owner, |
175 | | - group => $group, |
176 | | - umask => $umask, |
177 | | - cwd => $cwd, |
178 | | - environment => $environment, |
179 | | - timeout => $timeout, |
180 | | - path => $_path, |
181 | | - } |
| 181 | + if $_ensure != present and $_ensure != latest { |
| 182 | + $command = "${pip_install} ${install_args} ${pip_common_args}@${_ensure}#egg=${egg_name}" |
| 183 | + $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" |
182 | 184 | } else { |
183 | | - exec { "pip_install_${name}": |
184 | | - command => "${pip_install} ${install_args} ${pip_common_args}", |
185 | | - unless => "${pip_env} freeze --all | grep -i -e ${grep_regex}", |
186 | | - user => $owner, |
187 | | - group => $group, |
188 | | - umask => $umask, |
189 | | - cwd => $cwd, |
190 | | - environment => $environment, |
191 | | - timeout => $timeout, |
192 | | - path => $_path, |
193 | | - } |
| 185 | + $command = "${pip_install} ${install_args} ${pip_common_args}" |
| 186 | + $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" |
194 | 187 | } |
195 | 188 | } else { |
196 | | - case $ensure { |
| 189 | + case $_ensure { |
197 | 190 | /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.\w+\+?\w*(\.\w+)*)$/: { |
198 | 191 | # Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes |
199 | 192 | # Explicit version. |
200 | | - exec { "pip_install_${name}": |
201 | | - command => "${pip_install} ${install_args} ${pip_common_args}==${ensure}", |
202 | | - unless => "${pip_env} freeze --all | grep -i -e ${grep_regex} || ${pip_env} list | sed -e 's/[ ]\\+/==/' -e 's/[()]//g' | grep -i -e ${grep_regex}", |
203 | | - user => $owner, |
204 | | - group => $group, |
205 | | - umask => $umask, |
206 | | - cwd => $cwd, |
207 | | - environment => $environment, |
208 | | - timeout => $timeout, |
209 | | - path => $_path, |
210 | | - } |
| 193 | + $command = "${pip_install} ${install_args} ${pip_common_args}==${_ensure}" |
| 194 | + $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" |
211 | 195 | } |
212 | | -# |
| 196 | + |
213 | 197 | 'present': { |
214 | 198 | # Whatever version is available. |
215 | | - exec { "pip_install_${name}": |
216 | | - command => "${pip_install} ${pip_common_args}", |
217 | | - unless => "${pip_env} freeze --all | grep -i -e ${grep_regex} || ${pip_env} list | sed -e 's/[ ]\\+/==/' -e 's/[()]//g' | grep -i -e ${grep_regex}", |
218 | | - user => $owner, |
219 | | - group => $group, |
220 | | - umask => $umask, |
221 | | - cwd => $cwd, |
222 | | - environment => $environment, |
223 | | - timeout => $timeout, |
224 | | - path => $_path, |
225 | | - } |
| 199 | + $command = "${pip_install} ${pip_common_args}" |
| 200 | + $unless_command = "${pip_env} list | grep -i -e '${grep_regex}'" |
226 | 201 | } |
227 | 202 |
|
228 | 203 | 'latest': { |
229 | 204 | # Unfortunately this is the smartest way of getting the latest available package version with pip as of now |
230 | 205 | # Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns |
231 | 206 | # more than one line with paretheses. |
232 | | - $latest_version = join(["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${pkgname}==notreallyaversion 2>&1", |
| 207 | + $latest_version = join(["${pip_install} ${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1", |
233 | 208 | ' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"', |
234 | 209 | ' | tr -d "[:space:]"']) |
235 | 210 |
|
236 | 211 | # Packages with underscores in their names are listed with dashes in their place in `pip freeze` output |
237 | | - $pkgname_with_dashes = regsubst($pkgname, '_', '-', 'G') |
| 212 | + $pkgname_with_dashes = regsubst($real_pkgname, '_', '-', 'G') |
238 | 213 | $grep_regex_pkgname_with_dashes = "^${pkgname_with_dashes}==" |
239 | 214 | $installed_version = join(["${pip_env} freeze --all", |
240 | 215 | " | grep -i -e ${grep_regex_pkgname_with_dashes} | cut -d= -f3", |
241 | 216 | " | tr -d '[:space:]'"]) |
242 | 217 |
|
| 218 | + $command = "${pip_install} --upgrade ${pip_common_args}" |
243 | 219 | $unless_command = "[ \$(${latest_version}) = \$(${installed_version}) ]" |
244 | | - |
245 | | - # Latest version. |
246 | | - exec { "pip_install_${name}": |
247 | | - command => "${pip_install} --upgrade ${pip_common_args}", |
248 | | - unless => $unless_command, |
249 | | - user => $owner, |
250 | | - group => $group, |
251 | | - umask => $umask, |
252 | | - cwd => $cwd, |
253 | | - environment => $environment, |
254 | | - timeout => $timeout, |
255 | | - path => $_path, |
256 | | - } |
257 | 220 | } |
258 | 221 |
|
259 | 222 | default: { |
260 | 223 | # Anti-action, uninstall. |
261 | | - exec { "pip_uninstall_${name}": |
262 | | - command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}", |
263 | | - onlyif => "${pip_env} freeze --all | grep -i -e ${grep_regex}", |
264 | | - user => $owner, |
265 | | - group => $group, |
266 | | - umask => $umask, |
267 | | - cwd => $cwd, |
268 | | - environment => $environment, |
269 | | - timeout => $timeout, |
270 | | - path => $_path, |
271 | | - } |
| 224 | + $pip_exec_name = "pip_uninstall_${name}" |
| 225 | + $command = "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${name}" |
| 226 | + $unless_command = "! ${pip_env} list | grep -i -e '${grep_regex}'" |
272 | 227 | } |
273 | 228 | } |
274 | 229 | } |
| 230 | + |
| 231 | + exec { $pip_exec_name: |
| 232 | + command => $command, |
| 233 | + unless => $unless_command, |
| 234 | + user => $owner, |
| 235 | + group => $group, |
| 236 | + umask => $umask, |
| 237 | + cwd => $cwd, |
| 238 | + environment => $environment, |
| 239 | + timeout => $timeout, |
| 240 | + path => $_path, |
| 241 | + } |
| 242 | + |
275 | 243 | } |
0 commit comments