Skip to content

fix for #1192 #1218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Oct 6, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions pip/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,10 @@ def _link_sort_key(self, link_tuple):
if link == InfLink: # existing install
pri = 1
elif link.wheel:
# all wheel links are known to be supported at this stage
pri = -(link.wheel.support_index_min())
support_index = link.wheel.support_index_min()
if support_index is None:
raise InstallationError("%s is not a supported wheel for this platform. It can't be sorted." % link.wheel.filename)
pri = -(support_index)
else: # sdist
pri = -(support_num)
return (parsed_version, pri)
Expand Down Expand Up @@ -470,7 +472,10 @@ def _link_package_versions(self, link, search_name):
logger.debug('Skipping link %s; macosx10 one' % (link))
self.logged_links.add(link)
return []
if link.wheel and link.wheel.name.lower() == search_name.lower():
if link.wheel:
if link.wheel.name.lower() != search_name.lower():
logger.debug('Skipping link %s; wrong project name (not %s)' % (link, search_name))
return []
version = link.wheel.version
if not link.wheel.supported():
logger.debug('Skipping %s because it is not compatible with this Python' % link)
Expand Down
52 changes: 51 additions & 1 deletion tests/unit/test_finder.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import os
import pkg_resources
from pkg_resources import parse_version, Distribution
from pip.backwardcompat import urllib
from pip.req import InstallRequirement
from pip.index import PackageFinder, Link
from pip.exceptions import BestVersionAlreadyInstalled, DistributionNotFound
from pip.exceptions import BestVersionAlreadyInstalled, DistributionNotFound, InstallationError
from pip.util import Inf
from tests.lib.path import Path
from tests.lib import tests_data, path_to_url, find_links, find_links2
Expand Down Expand Up @@ -156,6 +157,13 @@ def test_link_sorting(self):
assert links == results == results2, results2


@patch('pip.pep425tags.supported_tags', [])
def test_link_sorting_raises_when_wheel_unsupported(self):
links = [(parse_version('1.0'), Link('simple-1.0-py2.py3-none-TEST.whl'), '1.0')]
finder = PackageFinder([], [], use_wheel=True)
assert_raises(InstallationError, finder._sort_versions, links)


def test_finder_priority_file_over_page():
"""Test PackageFinder prefers file links over equivalent page links"""
req = InstallRequirement.from_line('gmpy==1.15', None)
Expand Down Expand Up @@ -438,3 +446,45 @@ def test_finder_finds_external_links_without_hashes_scraped_all_all_insecure():
)
link = finder.find_requirement(req, False)
assert link.filename == "bar-4.0.tar.gz"

class test_link_package_versions(object):

# patch this for travis which has distribute in it's base env for now
@patch('pip.wheel.pkg_resources.get_distribution', lambda x: Distribution(project_name='setuptools', version='0.9'))
def setup(self):
self.version = '1.0'
self.parsed_version = pkg_resources.parse_version(self.version)
self.search_name = 'pytest'
self.finder = PackageFinder([], [], use_wheel=True)

def test_link_package_versions_match_wheel(self):
"""Test that 'pytest' archives match for 'pytest'"""

# TODO: Uncomment these, when #1217 is fixed
# link = Link('http:/yo/pytest-1.0.tar.gz')
# result = self.finder._link_package_versions(link, self.search_name)
# assert result == [(self.parsed_version, link, self.version)], result

link = Link('http:/yo/pytest-1.0-py2.py3-none-any.whl')
result = self.finder._link_package_versions(link, self.search_name)
assert result == [(self.parsed_version, link, self.version)], result

def test_link_package_versions_substring_fails(self):
"""Test that 'pytest<something> archives won't match for 'pytest'"""

# TODO: Uncomment these, when #1217 is fixed
# link = Link('http:/yo/pytest-xdist-1.0.tar.gz')
# result = self.finder._link_package_versions(link, self.search_name)
# assert result == [], result

# link = Link('http:/yo/pytest2-1.0.tar.gz')
# result = self.finder._link_package_versions(link, self.search_name)
# assert result == [], result

link = Link('http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl')
result = self.finder._link_package_versions(link, self.search_name)
assert result == [], result