Skip to content

Commit

Permalink
Try to fix some Python 3 issues.
Browse files Browse the repository at this point in the history
Dunno what to do about the Mercurial/Bazaar test failures under it.
  • Loading branch information
John Hensley committed Jun 26, 2012
1 parent 8e8b55f commit a6171f3
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
26 changes: 20 additions & 6 deletions pip/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,8 @@ def find_requirement(self, req, upgrade):

# Assign a preference value to all index, mirror, or find_links
# package sources. The lower the number, the higher the preference.
# Start at 1; if the desired version of a package is installed, it
# should win, so it's assigned a preference of zero.
origin_preferences = dict([(str(e[1]), e[0] + 1) for e in enumerate(all_index_urls + self.find_links)])
all_origins = reversed(all_index_urls + self.find_links)
origin_preferences = dict([(str(e[1]), e[0]) for e in enumerate(all_origins)])
logger.debug('Origin preferences: %s' % origin_preferences)

def mkurl_pypi_url(url):
Expand Down Expand Up @@ -172,15 +171,18 @@ def mkurl_pypi_url(url):
found_versions = file_versions + found_versions
all_versions = found_versions + page_versions + dependency_versions
applicable_versions = []

highest_preference = float('inf')
lowest_preference = float('-inf')
for (parsed_version, link, version) in all_versions:
if version not in req.req:
logger.info("Ignoring link %s, version %s doesn't match %s"
% (link, version, ','.join([''.join(s) for s in req.req.specs])))
continue
preference = Inf
preference = lowest_preference
if link is Inf:
# this version is currently installed; it wins.
preference = 0
preference = highest_preference
else:
for origin in origin_preferences.keys():
link_url = link.comes_from and link.comes_from.url or link.url
Expand All @@ -189,7 +191,7 @@ def mkurl_pypi_url(url):
break
applicable_versions.append((link, version, parsed_version, preference))
# sort applicable_versions by origin preference
applicable_versions = sorted(applicable_versions, key=operator.itemgetter(3))
applicable_versions = sorted(applicable_versions, key=operator.itemgetter(3), reverse=True)
# and then by version
applicable_versions = sorted(applicable_versions, key=operator.itemgetter(2), reverse=True)
existing_applicable = bool([link for link, version, parsed_version, preference in applicable_versions if link is Inf])
Expand Down Expand Up @@ -611,6 +613,18 @@ def __str__(self):
else:
return self.url

def __ge__(self, other):
return self.url >= other.url

def __gt__(self, other):
return self.url > other.url

def __le__(self, other):
return self.url <= other.url

def __lt__(self, other):
return self.url < other.url

def __repr__(self):
return '<Link %s>' % self

Expand Down
12 changes: 12 additions & 0 deletions pip/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ def __cmp__(self, a):
return 0
return 1

def __ge__(self, a):
return True

def __gt__(self, a):
return True

def __le__(self, a):
return False

def __lt__(self, a):
return False

def __repr__(self):
return 'Inf'

Expand Down
2 changes: 1 addition & 1 deletion tests/test_index_preference.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import re
import shutil

from test_pip import here, reset_env, run_pip
from tests.test_pip import here, reset_env, run_pip


def test_index_preference():
Expand Down

0 comments on commit a6171f3

Please sign in to comment.