Skip to content

Commit a64d25e

Browse files
author
Greg Dubicki
committed
Stop using 'pip search' for ensure => latest
because it does not work properly with devpi as own repo/PyPi mirror and is being considered to be deprecated in pip
1 parent 2f16648 commit a64d25e

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

manifests/pip.pp

+9-6
Original file line numberDiff line numberDiff line change
@@ -139,11 +139,6 @@
139139
default => "--index-url=${index}",
140140
}
141141

142-
$pypi_search_index = $index ? {
143-
false => '',
144-
default => "--index=${index}",
145-
}
146-
147142
$proxy_flag = $proxy ? {
148143
false => '',
149144
default => "--proxy=${proxy}",
@@ -271,10 +266,18 @@
271266
}
272267

273268
'latest': {
269+
# Unfortunately this is the smartest way of getting the latest available package version with pip as of now
270+
$latest_version = join(["${pip_env} install ${proxy_flag} ${pkgname}==notreallyaversion 2>&1",
271+
' | grep -oP "\(.*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"'])
272+
273+
# Packages with underscores in their names are listed with dashes in their place by `pip freeze`
274+
$pkgname_with_dashes = regsubst($pkgname, '_', '-', 'G')
275+
$installed_version = "${pip_env} freeze --all | grep -oP '(?i)(?<=${pkgname_with_dashes}==).*'"
276+
274277
# Latest version.
275278
exec { "pip_install_${name}":
276279
command => "${wheel_check} ; { ${pip_install} --upgrade \$wheel_support_flag ${pip_common_args} || ${pip_install} --upgrade ${pip_common_args} ;}",
277-
unless => "${pip_env} search ${pypi_search_index} ${proxy_flag} ${source} | grep -i INSTALLED.*latest",
280+
unless => "[ `${latest_version}` == `${installed_version}` ]",
278281
user => $owner,
279282
group => $group,
280283
umask => $umask,

spec/defines/pip_spec.rb

+15-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
let(:params) { { proxy: 'http://my.proxy:3128', ensure: 'latest' } }
8080

8181
it { is_expected.to contain_exec('pip_install_rpyc').with_command("pip wheel --help > /dev/null 2>&1 && { pip show wheel > /dev/null 2>&1 || wheel_support_flag='--no-binary :all:'; } ; { pip --log /tmp/pip.log install --upgrade $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --upgrade --proxy=http://my.proxy:3128 rpyc ;}") }
82-
it { is_expected.to contain_exec('pip_install_rpyc').with_unless('pip search --proxy=http://my.proxy:3128 rpyc | grep -i INSTALLED.*latest') }
82+
it { is_expected.to contain_exec('pip_install_rpyc').with_unless('[ `pip install --proxy=http://my.proxy:3128 rpyc==notreallyaversion 2>&1 | grep -oP "\(.*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"` == `pip freeze --all | grep -oP \'(?i)(?<=rpyc==).*\'` ]') }
8383
end
8484
end
8585

@@ -109,6 +109,20 @@
109109
it { is_expected.to contain_exec('pip_install_rpyc').with_path(['/opt/python3/bin', '/usr/local/bin', '/usr/bin', '/bin', '/usr/sbin']) }
110110
end
111111
end
112+
113+
describe 'install latest' do
114+
context 'does not use pip search' do
115+
let(:params) { { ensure: 'latest' } }
116+
117+
it { is_expected.not_to contain_exec('pip_install_rpyc').with_unless(%r{search}) }
118+
end
119+
context 'checks installed version of a package by converting underscores in its name with dashes' do
120+
let(:params) { { ensure: 'latest', pkgname: 'wordpress_json' } }
121+
122+
# yes, the exec title does not change if we use different pgkname
123+
it { is_expected.to contain_exec('pip_install_rpyc').with_unless(%r{wordpress-json}) }
124+
end
125+
end
112126
end
113127
end
114128

0 commit comments

Comments
 (0)