Skip to content

Commit

Permalink
use legacy pip resolver for pip versions < 21.1 > 20.2.4
Browse files Browse the repository at this point in the history
  • Loading branch information
saz committed Jul 25, 2022
1 parent ef2df5b commit 6dfeba6
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 2 deletions.
9 changes: 8 additions & 1 deletion manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -200,11 +200,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} ${proxy_flag} ${install_args} ${install_editable} ${real_pkgname}==notreallyaversion 2>&1",
"${pip_install} ${legacy_resolver} ${pypi_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:]"',
])
Expand Down
38 changes: 37 additions & 1 deletion spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -112,6 +113,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' } }

Expand Down Expand Up @@ -144,6 +151,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
Expand Down

0 comments on commit 6dfeba6

Please sign in to comment.