mirror of
https://github.com/pypa/pip
synced 2023-12-13 21:30:23 +01:00
parent
28f658f908
commit
f1bf7515c2
82
pip/index.py
82
pip/index.py
|
@ -17,7 +17,7 @@ from pip._vendor.six.moves.urllib import request as urllib_request
|
||||||
|
|
||||||
from pip.compat import ipaddress
|
from pip.compat import ipaddress
|
||||||
from pip.utils import (
|
from pip.utils import (
|
||||||
Inf, cached_property, splitext, normalize_path,
|
cached_property, splitext, normalize_path,
|
||||||
ARCHIVE_EXTENSIONS, SUPPORTED_EXTENSIONS, canonicalize_name)
|
ARCHIVE_EXTENSIONS, SUPPORTED_EXTENSIONS, canonicalize_name)
|
||||||
from pip.utils.deprecation import RemovedInPip9Warning
|
from pip.utils.deprecation import RemovedInPip9Warning
|
||||||
from pip.utils.logging import indent_log
|
from pip.utils.logging import indent_log
|
||||||
|
@ -233,9 +233,7 @@ class PackageFinder(object):
|
||||||
with the same version, would have to be considered equal
|
with the same version, would have to be considered equal
|
||||||
"""
|
"""
|
||||||
support_num = len(supported_tags)
|
support_num = len(supported_tags)
|
||||||
if candidate.location == INSTALLED_VERSION:
|
if candidate.location.is_wheel:
|
||||||
pri = 1
|
|
||||||
elif candidate.location.is_wheel:
|
|
||||||
# can raise InvalidWheelFilename
|
# can raise InvalidWheelFilename
|
||||||
wheel = Wheel(candidate.location.filename)
|
wheel = Wheel(candidate.location.filename)
|
||||||
if not wheel.supported():
|
if not wheel.supported():
|
||||||
|
@ -463,39 +461,9 @@ class PackageFinder(object):
|
||||||
x for x in all_versions if str(x.version) in _versions
|
x for x in all_versions if str(x.version) in _versions
|
||||||
]
|
]
|
||||||
|
|
||||||
if req.satisfied_by is not None:
|
|
||||||
# Finally add our existing versions to the front of our versions.
|
|
||||||
applicable_versions.insert(
|
|
||||||
0,
|
|
||||||
InstallationCandidate(
|
|
||||||
req.name,
|
|
||||||
req.satisfied_by.version,
|
|
||||||
INSTALLED_VERSION,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
existing_applicable = True
|
|
||||||
else:
|
|
||||||
existing_applicable = False
|
|
||||||
|
|
||||||
applicable_versions = self._sort_versions(applicable_versions)
|
applicable_versions = self._sort_versions(applicable_versions)
|
||||||
|
|
||||||
if not upgrade and existing_applicable:
|
if req.satisfied_by is None and not applicable_versions:
|
||||||
if applicable_versions[0].location is INSTALLED_VERSION:
|
|
||||||
logger.debug(
|
|
||||||
'Existing installed version (%s) is most up-to-date and '
|
|
||||||
'satisfies requirement',
|
|
||||||
req.satisfied_by.version,
|
|
||||||
)
|
|
||||||
else:
|
|
||||||
logger.debug(
|
|
||||||
'Existing installed version (%s) satisfies requirement '
|
|
||||||
'(most up-to-date version is %s)',
|
|
||||||
req.satisfied_by.version,
|
|
||||||
applicable_versions[0][2],
|
|
||||||
)
|
|
||||||
return None
|
|
||||||
|
|
||||||
if not applicable_versions:
|
|
||||||
logger.critical(
|
logger.critical(
|
||||||
'Could not find a version that satisfies the requirement %s '
|
'Could not find a version that satisfies the requirement %s '
|
||||||
'(from versions: %s)',
|
'(from versions: %s)',
|
||||||
|
@ -512,23 +480,44 @@ class PackageFinder(object):
|
||||||
'No matching distribution found for %s' % req
|
'No matching distribution found for %s' % req
|
||||||
)
|
)
|
||||||
|
|
||||||
if applicable_versions[0].location is INSTALLED_VERSION:
|
best_installed = False
|
||||||
|
if req.satisfied_by and (
|
||||||
|
not applicable_versions or
|
||||||
|
applicable_versions[0].version <= req.satisfied_by.version):
|
||||||
|
best_installed = True
|
||||||
|
|
||||||
|
if not upgrade and req.satisfied_by is not None:
|
||||||
|
if best_installed:
|
||||||
|
logger.debug(
|
||||||
|
'Existing installed version (%s) is most up-to-date and '
|
||||||
|
'satisfies requirement',
|
||||||
|
req.satisfied_by.version,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
logger.debug(
|
||||||
|
'Existing installed version (%s) satisfies requirement '
|
||||||
|
'(most up-to-date version is %s)',
|
||||||
|
req.satisfied_by.version,
|
||||||
|
applicable_versions[0].version,
|
||||||
|
)
|
||||||
|
return None
|
||||||
|
|
||||||
|
if best_installed:
|
||||||
# We have an existing version, and its the best version
|
# We have an existing version, and its the best version
|
||||||
logger.debug(
|
logger.debug(
|
||||||
'Installed version (%s) is most up-to-date (past versions: '
|
'Installed version (%s) is most up-to-date (past versions: '
|
||||||
'%s)',
|
'%s)',
|
||||||
req.satisfied_by.version,
|
req.satisfied_by.version,
|
||||||
', '.join(str(i.version) for i in applicable_versions[1:]) or
|
', '.join(str(i.version) for i in applicable_versions) or
|
||||||
"none",
|
"none",
|
||||||
)
|
)
|
||||||
raise BestVersionAlreadyInstalled
|
raise BestVersionAlreadyInstalled
|
||||||
|
|
||||||
if len(applicable_versions) > 1:
|
logger.debug(
|
||||||
logger.debug(
|
'Using version %s (newest of versions: %s)',
|
||||||
'Using version %s (newest of versions: %s)',
|
applicable_versions[0].version,
|
||||||
applicable_versions[0].version,
|
', '.join(str(i.version) for i in applicable_versions)
|
||||||
', '.join(str(i.version) for i in applicable_versions)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
selected_version = applicable_versions[0].location
|
selected_version = applicable_versions[0].location
|
||||||
|
|
||||||
|
@ -873,7 +862,7 @@ class Link(object):
|
||||||
def __init__(self, url, comes_from=None):
|
def __init__(self, url, comes_from=None):
|
||||||
|
|
||||||
# url can be a UNC windows share
|
# url can be a UNC windows share
|
||||||
if url != Inf and url.startswith('\\\\'):
|
if url.startswith('\\\\'):
|
||||||
url = path_to_url(url)
|
url = path_to_url(url)
|
||||||
|
|
||||||
self.url = url
|
self.url = url
|
||||||
|
@ -1002,11 +991,6 @@ class Link(object):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
||||||
# An object to represent the "link" for the installed version of a requirement.
|
|
||||||
# Using Inf as the url makes it sort higher.
|
|
||||||
INSTALLED_VERSION = Link(Inf)
|
|
||||||
|
|
||||||
|
|
||||||
FormatControl = namedtuple('FormatControl', 'no_binary only_binary')
|
FormatControl = namedtuple('FormatControl', 'no_binary only_binary')
|
||||||
"""This object has two fields, no_binary and only_binary.
|
"""This object has two fields, no_binary and only_binary.
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ else:
|
||||||
from io import StringIO
|
from io import StringIO
|
||||||
|
|
||||||
__all__ = ['rmtree', 'display_path', 'backup_dir',
|
__all__ = ['rmtree', 'display_path', 'backup_dir',
|
||||||
'ask', 'Inf', 'splitext',
|
'ask', 'splitext',
|
||||||
'format_size', 'is_installable_dir',
|
'format_size', 'is_installable_dir',
|
||||||
'is_svn_page', 'file_contents',
|
'is_svn_page', 'file_contents',
|
||||||
'split_leading_dir', 'has_leading_dir',
|
'split_leading_dir', 'has_leading_dir',
|
||||||
|
@ -154,38 +154,6 @@ def ask(message, options):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
class _Inf(object):
|
|
||||||
"""I am bigger than everything!"""
|
|
||||||
|
|
||||||
def __eq__(self, other):
|
|
||||||
if self is other:
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def __ne__(self, other):
|
|
||||||
return not self.__eq__(other)
|
|
||||||
|
|
||||||
def __lt__(self, other):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def __le__(self, other):
|
|
||||||
return False
|
|
||||||
|
|
||||||
def __gt__(self, other):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __ge__(self, other):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def __repr__(self):
|
|
||||||
return 'Inf'
|
|
||||||
|
|
||||||
|
|
||||||
Inf = _Inf() # this object is not currently used as a sortable in our code
|
|
||||||
del _Inf
|
|
||||||
|
|
||||||
|
|
||||||
def format_size(bytes):
|
def format_size(bytes):
|
||||||
if bytes > 1000 * 1000:
|
if bytes > 1000 * 1000:
|
||||||
return '%.1fMB' % (bytes / 1000.0 / 1000)
|
return '%.1fMB' % (bytes / 1000.0 / 1000)
|
||||||
|
|
|
@ -11,7 +11,6 @@ from pip.index import (
|
||||||
from pip.exceptions import (
|
from pip.exceptions import (
|
||||||
BestVersionAlreadyInstalled, DistributionNotFound, InstallationError,
|
BestVersionAlreadyInstalled, DistributionNotFound, InstallationError,
|
||||||
)
|
)
|
||||||
from pip.utils import Inf
|
|
||||||
from pip.download import PipSession
|
from pip.download import PipSession
|
||||||
|
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
|
@ -225,7 +224,6 @@ class TestWheel:
|
||||||
Test link sorting
|
Test link sorting
|
||||||
"""
|
"""
|
||||||
links = [
|
links = [
|
||||||
InstallationCandidate("simple", "2.0", Link(Inf)),
|
|
||||||
InstallationCandidate("simple", "2.0", Link('simple-2.0.tar.gz')),
|
InstallationCandidate("simple", "2.0", Link('simple-2.0.tar.gz')),
|
||||||
InstallationCandidate(
|
InstallationCandidate(
|
||||||
"simple",
|
"simple",
|
||||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
||||||
|
|
||||||
from pip.download import PipSession
|
from pip.download import PipSession
|
||||||
from pip.index import HTMLPage
|
from pip.index import HTMLPage
|
||||||
from pip.index import PackageFinder, Link, INSTALLED_VERSION
|
from pip.index import PackageFinder, Link
|
||||||
|
|
||||||
|
|
||||||
def test_sort_locations_file_expand_dir(data):
|
def test_sort_locations_file_expand_dir(data):
|
||||||
|
@ -27,11 +27,6 @@ def test_sort_locations_file_not_find_link(data):
|
||||||
assert urls and not files, "urls, but not files should have been found"
|
assert urls and not files, "urls, but not files should have been found"
|
||||||
|
|
||||||
|
|
||||||
def test_INSTALLED_VERSION_greater():
|
|
||||||
"""Test INSTALLED_VERSION compares greater."""
|
|
||||||
assert INSTALLED_VERSION > Link("some link")
|
|
||||||
|
|
||||||
|
|
||||||
class TestLink(object):
|
class TestLink(object):
|
||||||
|
|
||||||
def test_splitext(self):
|
def test_splitext(self):
|
||||||
|
|
|
@ -12,7 +12,7 @@ import tempfile
|
||||||
import pytest
|
import pytest
|
||||||
|
|
||||||
from mock import Mock, patch
|
from mock import Mock, patch
|
||||||
from pip.utils import (egg_link_path, Inf, get_installed_distributions,
|
from pip.utils import (egg_link_path, get_installed_distributions,
|
||||||
untar_file, unzip_file, rmtree, normalize_path)
|
untar_file, unzip_file, rmtree, normalize_path)
|
||||||
from pip.operations.freeze import freeze_excludes
|
from pip.operations.freeze import freeze_excludes
|
||||||
|
|
||||||
|
@ -151,16 +151,6 @@ class Tests_EgglinkPath:
|
||||||
assert egg_link_path(self.mock_dist) is None
|
assert egg_link_path(self.mock_dist) is None
|
||||||
|
|
||||||
|
|
||||||
def test_Inf_greater():
|
|
||||||
"""Test Inf compares greater."""
|
|
||||||
assert Inf > object()
|
|
||||||
|
|
||||||
|
|
||||||
def test_Inf_equals_Inf():
|
|
||||||
"""Test Inf compares greater."""
|
|
||||||
assert Inf == Inf
|
|
||||||
|
|
||||||
|
|
||||||
@patch('pip.utils.dist_in_usersite')
|
@patch('pip.utils.dist_in_usersite')
|
||||||
@patch('pip.utils.dist_is_local')
|
@patch('pip.utils.dist_is_local')
|
||||||
@patch('pip.utils.dist_is_editable')
|
@patch('pip.utils.dist_is_editable')
|
||||||
|
|
Loading…
Reference in a new issue