diff --git a/manifests/pip.pp b/manifests/pip.pp index a6b92c66..488faf11 100644 --- a/manifests/pip.pp +++ b/manifests/pip.pp @@ -207,11 +207,18 @@ } 'latest': { + $pip_version = $facts['pip_version'] + if $pip_version and versioncmp($pip_version, '21.1') == -1 and versioncmp($pip_version, '20.2.4') == 1 { + $legacy_resolver = '--use-deprecated=legacy-resolver' + } else { + $legacy_resolver = '' + } + # Unfortunately this is the smartest way of getting the latest available package version with pip as of now # Note: we DO need to repeat ourselves with "from version" in both grep and sed as on some systems pip returns # more than one line with paretheses. $latest_version = join( [ - "${pip_install} ${pypi_index} ${pypi_extra_index} ${proxy_flag}", + "${pip_install} ${legacy_resolver} ${pypi_index} ${pypi_extra_index} ${proxy_flag}", " ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1", ' | grep -oP "\(from versions: .*\)" | sed -E "s/\(from versions: (.*?, )*(.*)\)/\2/g"', ' | tr -d "[:space:]"', diff --git a/spec/defines/pip_spec.rb b/spec/defines/pip_spec.rb index 52d43e91..d7115427 100644 --- a/spec/defines/pip_spec.rb +++ b/spec/defines/pip_spec.rb @@ -20,7 +20,8 @@ operatingsystem: 'Debian', operatingsystemrelease: '6', path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', - concat_basedir: '/dne' + concat_basedir: '/dne', + pip_version: '18.1' } end @@ -126,6 +127,12 @@ end describe 'install latest' do + context 'does not use legacy resolver in unless' do + let(:params) { { ensure: 'latest' } } + + it { is_expected.not_to contain_exec('pip_install_rpyc').with_unless(%r{--use-deprecated=legacy-resolver}) } + end + context 'does not use pip search in unless' do let(:params) { { ensure: 'latest' } } @@ -158,6 +165,35 @@ end end end + + context 'on Debian OS with pip_version 20.3.4' do + let :facts do + { + id: 'root', + kernel: 'Linux', + lsbdistcodename: 'buster', + os: { + family: 'Debian', + release: { major: '10' }, + }, + osfamily: 'Debian', + operatingsystem: 'Debian', + operatingsystemrelease: '10.12', + path: '/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin', + concat_basedir: '/dne', + pip_version: '20.3.4' + } + end + + describe 'install latest' do + context 'with legacy resolver in unless cmd' do + let(:params) { { ensure: 'latest' } } + + it { is_expected.to compile.with_all_deps } + it { is_expected.to contain_exec('pip_install_rpyc').with_unless(%r{--use-deprecated=legacy-resolver}) } + end + end + end end describe 'python::pip', type: :define do