Skip to content

Commit b40fde4

Browse files
author
Nathan Sullivan
committed
add support for explicit version handling with ensure parameter for pip packages
1 parent ef4c506 commit b40fde4

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

manifests/pip.pp

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -77,18 +77,29 @@
7777
default => "--proxy=${proxy}",
7878
}
7979

80-
$grep_regex = $pkgname ? {
81-
/==/ => "^${pkgname}\$",
82-
default => "^${pkgname}==",
80+
# If pkgname is not specified, use name (title) instead.
81+
$use_pkgname = $pkgname ? {
82+
undef => $name,
83+
default => $pkgname
84+
}
85+
86+
# Check if searching by explicit version.
87+
if $ensure =~ /^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/ {
88+
$grep_regex = "^${use_pkgname}==${ensure}\$"
89+
} else {
90+
$grep_regex = $use_pkgname ? {
91+
/==/ => "^${use_pkgname}\$",
92+
default => "^${use_pkgname}==",
93+
}
8394
}
8495

8596
$egg_name = $egg ? {
86-
false => $pkgname,
97+
false => $use_pkgname,
8798
default => $egg
8899
}
89100

90101
$source = $url ? {
91-
false => $pkgname,
102+
false => $use_pkgname,
92103
default => "${url}#egg=${egg_name}",
93104
}
94105

@@ -108,7 +119,20 @@
108119

109120

110121
case $ensure {
122+
/^((19|20)[0-9][0-9]-(0[1-9]|1[1-2])-([0-2][1-9]|3[0-1])|[0-9]+\.[0-9]+(\.[0-9]+)?)$/: {
123+
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
124+
# Explicit version.
125+
exec { "pip_install_${name}":
126+
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${source}==${ensure}",
127+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
128+
user => $owner,
129+
environment => $environment,
130+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
131+
}
132+
}
133+
111134
present: {
135+
# Whatever version is available.
112136
exec { "pip_install_${name}":
113137
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${source}",
114138
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
@@ -119,6 +143,7 @@
119143
}
120144

121145
latest: {
146+
# Latest version.
122147
exec { "pip_install_${name}":
123148
command => "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} wheel --version > /dev/null 2>&1 || wheel_support_flag='--no-use-wheel'; } ; ${pip_env} --log ${cwd}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${source}",
124149
user => $owner,
@@ -128,8 +153,9 @@
128153
}
129154

130155
default: {
156+
# Anti-action, uninstall.
131157
exec { "pip_uninstall_${name}":
132-
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${pkgname}",
158+
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag} ${use_pkgname}",
133159
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
134160
user => $owner,
135161
environment => $environment,

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy