Skip to content
This repository was archived by the owner on Oct 18, 2022. It is now read-only.

Commit cb35dfe

Browse files
author
batkinson
committed
Add pip install support for "ensure => <Version>" when using VCS source/URLs
1 parent 35810f9 commit cb35dfe

File tree

1 file changed

+72
-47
lines changed

1 file changed

+72
-47
lines changed

manifests/pip.pp

Lines changed: 72 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -153,60 +153,85 @@
153153
# version, this makes sure we only use wheels if they are supported and
154154
# installed
155155

156-
157-
case $ensure {
158-
/^((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]+)?)$/: {
159-
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
160-
# Explicit version.
161-
exec { "pip_install_${name}":
162-
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 ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
163-
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
164-
user => $owner,
165-
cwd => $cwd,
166-
environment => $environment,
167-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
168-
timeout => $timeout,
169-
}
156+
# Explicit version out of VCS when PIP supported URL is provided
157+
if $source =~ /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp)(:\/\/).+$/ {
158+
if $ensure != present and $ensure != latest {
159+
exec { "pip_install_${name}":
160+
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 ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}@${ensure} ;}",
161+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
162+
user => $owner,
163+
cwd => $cwd,
164+
environment => $environment,
165+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
166+
timeout => $timeout,
167+
}
168+
}
169+
else {
170+
exec { "pip_install_${name}":
171+
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 ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
172+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
173+
user => $owner,
174+
cwd => $cwd,
175+
environment => $environment,
176+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
177+
timeout => $timeout,
178+
}
170179
}
180+
}
181+
else {
182+
case $ensure {
183+
/^((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]+)?)$/: {
184+
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
185+
# Explicit version.
186+
exec { "pip_install_${name}":
187+
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 ${log}/pip.log install ${install_args} \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} || ${pip_env} --log ${log}/pip.log install ${install_args} ${proxy_flag} ${install_args} ${install_editable} ${source}==${ensure} ;}",
188+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
189+
user => $owner,
190+
cwd => $cwd,
191+
environment => $environment,
192+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
193+
timeout => $timeout,
194+
}
195+
}
171196

172-
present: {
173-
# Whatever version is available.
174-
exec { "pip_install_${name}":
175-
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 ${log}/pip.log install \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
176-
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
177-
user => $owner,
178-
cwd => $cwd,
179-
environment => $environment,
180-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
181-
timeout => $timeout,
197+
present: {
198+
# Whatever version is available.
199+
exec { "pip_install_${name}":
200+
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 ${log}/pip.log install \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
201+
unless => "${pip_env} freeze | grep -i -e ${grep_regex}",
202+
user => $owner,
203+
cwd => $cwd,
204+
environment => $environment,
205+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
206+
timeout => $timeout,
207+
}
182208
}
183-
}
184209

185-
latest: {
186-
# Latest version.
187-
exec { "pip_install_${name}":
188-
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 ${log}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
189-
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
190-
user => $owner,
191-
cwd => $cwd,
192-
environment => $environment,
193-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
194-
timeout => $timeout,
210+
latest: {
211+
# Latest version.
212+
exec { "pip_install_${name}":
213+
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 ${log}/pip.log install --upgrade \$wheel_support_flag ${proxy_flag} ${install_args} ${install_editable} ${source} || ${pip_env} --log ${log}/pip.log install --upgrade ${proxy_flag} ${install_args} ${install_editable} ${source} ;}",
214+
unless => "${pip_env} search ${source} | grep -i INSTALLED | grep -i latest",
215+
user => $owner,
216+
cwd => $cwd,
217+
environment => $environment,
218+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
219+
timeout => $timeout,
220+
}
195221
}
196-
}
197222

198-
default: {
199-
# Anti-action, uninstall.
200-
exec { "pip_uninstall_${name}":
201-
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag}",
202-
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
203-
user => $owner,
204-
cwd => $cwd,
205-
environment => $environment,
206-
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
207-
timeout => $timeout,
223+
default: {
224+
# Anti-action, uninstall.
225+
exec { "pip_uninstall_${name}":
226+
command => "echo y | ${pip_env} uninstall ${uninstall_args} ${proxy_flag}",
227+
onlyif => "${pip_env} freeze | grep -i -e ${grep_regex}",
228+
user => $owner,
229+
cwd => $cwd,
230+
environment => $environment,
231+
path => ['/usr/local/bin','/usr/bin','/bin', '/usr/sbin'],
232+
timeout => $timeout,
233+
}
208234
}
209235
}
210236
}
211-
212237
}

0 commit comments

Comments
 (0)