Skip to content

Commit

Permalink
Merge pull request #483 from asottile/pip_can_use_wheels
Browse files Browse the repository at this point in the history
Modern pip can install wheels without wheel installed
  • Loading branch information
alexjfisher authored May 24, 2019
2 parents d0c3a99 + c3bb6b3 commit e9dbed0
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 24 deletions.
25 changes: 5 additions & 20 deletions manifests/pip.pp
Original file line number Diff line number Diff line change
Expand Up @@ -162,29 +162,14 @@
default => "${url}#egg=${egg_name}",
}

# We need to jump through hoops to make sure we issue the correct pip command
# depending on wheel support and versions.
#
# Pip does not support wheels prior to version 1.4.0
# Pip wheels require setuptools/distribute > 0.8
# Python 2.6 and older does not support setuptools/distribute > 0.8
# Pip >= 1.5 tries to use wheels by default, even if wheel package is not
# installed, in this case the --no-use-wheel flag needs to be passed
# Versions prior to 1.5 don't support the --no-use-wheel flag
#
# To check for this we test for wheel parameter using help and then using
# show, this makes sure we only use wheels if they are supported and
# installed
$wheel_check = "${pip_env} wheel --help > /dev/null 2>&1 && { ${pip_env} show wheel > /dev/null 2>&1 || wheel_support_flag='--no-binary :all:'; }"

$pip_install = "${pip_env} --log ${log}/pip.log install"
$pip_common_args = "${pypi_index} ${proxy_flag} ${install_args} ${install_editable} ${source}"

# Explicit version out of VCS when PIP supported URL is provided
if $source =~ /^(git\+|hg\+|bzr\+|svn\+)(http|https|ssh|svn|sftp|ftp|lp)(:\/\/).+$/ {
if $ensure != present and $ensure != latest {
exec { "pip_install_${name}":
command => "${wheel_check} ; { ${pip_install} ${install_args} \$wheel_support_flag ${pip_common_args}@${ensure}#egg=${egg_name} || ${pip_install} ${install_args} ${pip_common_args}@${ensure}#egg=${egg_name} ;}",
command => "${pip_install} ${install_args} ${pip_common_args}@${ensure}#egg=${egg_name}",
unless => "${pip_env} freeze --all | grep -i -e ${grep_regex}",
user => $owner,
group => $group,
Expand All @@ -196,7 +181,7 @@
}
} else {
exec { "pip_install_${name}":
command => "${wheel_check} ; { ${pip_install} ${install_args} \$wheel_support_flag ${pip_common_args} || ${pip_install} ${install_args} ${pip_common_args} ;}",
command => "${pip_install} ${install_args} ${pip_common_args}",
unless => "${pip_env} freeze --all | grep -i -e ${grep_regex}",
user => $owner,
group => $group,
Expand All @@ -213,7 +198,7 @@
# Version formats as per http://guide.python-distribute.org/specification.html#standard-versioning-schemes
# Explicit version.
exec { "pip_install_${name}":
command => "${wheel_check} ; { ${pip_install} ${install_args} \$wheel_support_flag ${pip_common_args}==${ensure} || ${pip_install} ${install_args} ${pip_common_args}==${ensure} ;}",
command => "${pip_install} ${install_args} ${pip_common_args}==${ensure}",
unless => "${pip_env} freeze --all | grep -i -e ${grep_regex} || ${pip_env} list | sed -e 's/[ ]\\+/==/' -e 's/[()]//g' | grep -i -e ${grep_regex}",
user => $owner,
group => $group,
Expand All @@ -228,7 +213,7 @@
'present': {
# Whatever version is available.
exec { "pip_install_${name}":
command => "${wheel_check} ; { ${pip_install} \$wheel_support_flag ${pip_common_args} || ${pip_install} ${pip_common_args} ;}",
command => "${pip_install} ${pip_common_args}",
unless => "${pip_env} freeze --all | grep -i -e ${grep_regex} || ${pip_env} list | sed -e 's/[ ]\\+/==/' -e 's/[()]//g' | grep -i -e ${grep_regex}",
user => $owner,
group => $group,
Expand Down Expand Up @@ -259,7 +244,7 @@

# Latest version.
exec { "pip_install_${name}":
command => "${wheel_check} ; { ${pip_install} --upgrade \$wheel_support_flag ${pip_common_args} || ${pip_install} --upgrade ${pip_common_args} ;}",
command => "${pip_install} --upgrade ${pip_common_args}",
unless => $unless_command,
user => $owner,
group => $group,
Expand Down
8 changes: 4 additions & 4 deletions spec/defines/pip_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
context 'adds proxy to install command if proxy set' do
let(:params) { { proxy: 'http://my.proxy:3128' } }

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 $wheel_support_flag --proxy=http://my.proxy:3128 rpyc || pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc ;}") }
it { is_expected.to contain_exec('pip_install_rpyc').with_command('pip --log /tmp/pip.log install --proxy=http://my.proxy:3128 rpyc') }
end
end

Expand All @@ -80,7 +80,7 @@
context 'adds index to install command if index set' do
let(:params) { { index: 'http://www.example.com/simple/' } }

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 $wheel_support_flag --index-url=http://www.example.com/simple/ rpyc || pip --log /tmp/pip.log install --index-url=http://www.example.com/simple/ rpyc ;}") }
it { is_expected.to contain_exec('pip_install_rpyc').with_command('pip --log /tmp/pip.log install --index-url=http://www.example.com/simple/ rpyc') }
end
end

Expand Down Expand Up @@ -133,12 +133,12 @@
context 'suceeds with no extras' do
let(:params) { {} }

it { is_expected.to contain_exec('pip_install_requests').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 $wheel_support_flag requests || pip --log /tmp/pip.log install requests ;}") }
it { is_expected.to contain_exec('pip_install_requests').with_command('pip --log /tmp/pip.log install requests') }
end
context 'succeeds with extras' do
let(:params) { { extras: ['security'] } }

it { is_expected.to contain_exec('pip_install_requests').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 $wheel_support_flag requests[security] || pip --log /tmp/pip.log install requests[security] ;}") }
it { is_expected.to contain_exec('pip_install_requests').with_command('pip --log /tmp/pip.log install requests[security]') }
end
end
end
Expand Down

0 comments on commit e9dbed0

Please sign in to comment.