Skip to content

Commit

Permalink
Rename _link_package_versions() to evaluate_link().
Browse files Browse the repository at this point in the history
  • Loading branch information
cjerdonek committed May 7, 2019
1 parent 651d6fe commit 10c68e6
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 15 deletions.
32 changes: 22 additions & 10 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,10 @@ def _get_html_page(link, session=None):

class CandidateEvaluator(object):

_py_version_re = re.compile(r'-py([123]\.?[0-9]?)$')
"""
Responsible for filtering and sorting candidates for installation based
on what tags are valid.
"""

def __init__(
self,
Expand All @@ -269,6 +272,11 @@ def __init__(
self._prefer_binary = prefer_binary
self._valid_tags = valid_tags

# We compile the regex here instead of as a class attribute so as
# not to not impact pip start-up time. This is also okay because
# CandidateEvaluator is generally instantiated only once per pip
# invocation (when PackageFinder is instantiated).
self._py_version_re = re.compile(r'-py([123]\.?[0-9]?)$')
# These are boring links that have already been logged somehow.
self._logged_links = set() # type: Set[Link]

Expand All @@ -278,13 +286,17 @@ def _log_skipped_link(self, link, reason):
logger.debug('Skipping link %s; %s', link, reason)
self._logged_links.add(link)

def is_wheel_supported(self, wheel):
def _is_wheel_supported(self, wheel):
# type: (Wheel) -> bool
return wheel.supported(self._valid_tags)

def _link_package_versions(self, link, search):
def evaluate_link(self, link, search):
# type: (Link, Search) -> Optional[InstallationCandidate]
"""Return an InstallationCandidate or None"""
"""
Determine whether a link is a candidate for installation.
Returns an InstallationCandidate if so, otherwise None.
"""
version = None
if link.egg_fragment:
egg_info = link.egg_fragment
Expand Down Expand Up @@ -318,7 +330,7 @@ def _link_package_versions(self, link, search):
link, 'wrong project name (not %s)' % search.supplied)
return None

if not self.is_wheel_supported(wheel):
if not self._is_wheel_supported(wheel):
self._log_skipped_link(
link, 'it is not compatible with this Python')
return None
Expand Down Expand Up @@ -384,7 +396,7 @@ def _sort_key(self, candidate):
if candidate.location.is_wheel:
# can raise InvalidWheelFilename
wheel = Wheel(candidate.location.filename)
if not wheel.supported(self._valid_tags):
if not self._is_wheel_supported(wheel):
raise UnsupportedWheel(
"%s is not a supported wheel for this platform. It "
"can't be sorted." % wheel.filename
Expand Down Expand Up @@ -762,7 +774,7 @@ def find_all_candidates(self, project_name):
This checks index_urls and find_links.
All versions found are returned as an InstallationCandidate list.
See _link_package_versions for details on which files are accepted
See evaluate_link() for details on which files are accepted
"""
index_locations = self._get_index_urls_locations(project_name)
index_file_loc, index_url_loc = self._sort_locations(index_locations)
Expand Down Expand Up @@ -962,9 +974,9 @@ def _package_versions(
# type: (...) -> List[InstallationCandidate]
result = []
for link in self._sort_links(links):
v = self.candidate_evaluator._link_package_versions(link, search)
if v is not None:
result.append(v)
candidate = self.candidate_evaluator.evaluate_link(link, search)
if candidate is not None:
result.append(candidate)
return result


Expand Down
10 changes: 5 additions & 5 deletions tests/unit/test_finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -460,7 +460,7 @@ def test_finder_installs_pre_releases_with_version_spec():
assert link.url == "https://foo/bar-2.0b1.tar.gz"


class TestLinkPackageVersions(object):
class TestCandidateEvaluator(object):

# patch this for travis which has distribute in its base env for now
@patch(
Expand All @@ -481,15 +481,15 @@ def setup(self):
'http:/yo/pytest-1.0-py2.py3-none-any.whl',
],
)
def test_link_package_versions_match(self, url):
def test_evaluate_link__match(self, url):
"""Test that 'pytest' archives match for 'pytest'"""
link = Link(url)
search = Search(
supplied=self.search_name,
canonical=self.canonical_name,
formats=['source', 'binary'],
)
result = self.evaluator._link_package_versions(link, search)
result = self.evaluator.evaluate_link(link, search)
expected = InstallationCandidate(self.search_name, self.version, link)
assert result == expected, result

Expand All @@ -502,15 +502,15 @@ def test_link_package_versions_match(self, url):
'http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl',
],
)
def test_link_package_versions_substring_fails(self, url):
def test_evaluate_link__substring_fails(self, url):
"""Test that 'pytest<something> archives won't match for 'pytest'."""
link = Link(url)
search = Search(
supplied=self.search_name,
canonical=self.canonical_name,
formats=['source', 'binary'],
)
result = self.evaluator._link_package_versions(link, search)
result = self.evaluator.evaluate_link(link, search)
assert result is None, result


Expand Down

0 comments on commit 10c68e6

Please sign in to comment.