Skip to content

Commit 10c68e6

Browse files
committed
Rename _link_package_versions() to evaluate_link().
1 parent 651d6fe commit 10c68e6

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

src/pip/_internal/index.py

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,10 @@ def _get_html_page(link, session=None):
258258

259259
class CandidateEvaluator(object):
260260

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

263266
def __init__(
264267
self,
@@ -269,6 +272,11 @@ def __init__(
269272
self._prefer_binary = prefer_binary
270273
self._valid_tags = valid_tags
271274

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

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

281-
def is_wheel_supported(self, wheel):
289+
def _is_wheel_supported(self, wheel):
282290
# type: (Wheel) -> bool
283291
return wheel.supported(self._valid_tags)
284292

285-
def _link_package_versions(self, link, search):
293+
def evaluate_link(self, link, search):
286294
# type: (Link, Search) -> Optional[InstallationCandidate]
287-
"""Return an InstallationCandidate or None"""
295+
"""
296+
Determine whether a link is a candidate for installation.
297+
298+
Returns an InstallationCandidate if so, otherwise None.
299+
"""
288300
version = None
289301
if link.egg_fragment:
290302
egg_info = link.egg_fragment
@@ -318,7 +330,7 @@ def _link_package_versions(self, link, search):
318330
link, 'wrong project name (not %s)' % search.supplied)
319331
return None
320332

321-
if not self.is_wheel_supported(wheel):
333+
if not self._is_wheel_supported(wheel):
322334
self._log_skipped_link(
323335
link, 'it is not compatible with this Python')
324336
return None
@@ -384,7 +396,7 @@ def _sort_key(self, candidate):
384396
if candidate.location.is_wheel:
385397
# can raise InvalidWheelFilename
386398
wheel = Wheel(candidate.location.filename)
387-
if not wheel.supported(self._valid_tags):
399+
if not self._is_wheel_supported(wheel):
388400
raise UnsupportedWheel(
389401
"%s is not a supported wheel for this platform. It "
390402
"can't be sorted." % wheel.filename
@@ -762,7 +774,7 @@ def find_all_candidates(self, project_name):
762774
This checks index_urls and find_links.
763775
All versions found are returned as an InstallationCandidate list.
764776
765-
See _link_package_versions for details on which files are accepted
777+
See evaluate_link() for details on which files are accepted
766778
"""
767779
index_locations = self._get_index_urls_locations(project_name)
768780
index_file_loc, index_url_loc = self._sort_locations(index_locations)
@@ -962,9 +974,9 @@ def _package_versions(
962974
# type: (...) -> List[InstallationCandidate]
963975
result = []
964976
for link in self._sort_links(links):
965-
v = self.candidate_evaluator._link_package_versions(link, search)
966-
if v is not None:
967-
result.append(v)
977+
candidate = self.candidate_evaluator.evaluate_link(link, search)
978+
if candidate is not None:
979+
result.append(candidate)
968980
return result
969981

970982

tests/unit/test_finder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ def test_finder_installs_pre_releases_with_version_spec():
460460
assert link.url == "https://foo/bar-2.0b1.tar.gz"
461461

462462

463-
class TestLinkPackageVersions(object):
463+
class TestCandidateEvaluator(object):
464464

465465
# patch this for travis which has distribute in its base env for now
466466
@patch(
@@ -481,15 +481,15 @@ def setup(self):
481481
'http:/yo/pytest-1.0-py2.py3-none-any.whl',
482482
],
483483
)
484-
def test_link_package_versions_match(self, url):
484+
def test_evaluate_link__match(self, url):
485485
"""Test that 'pytest' archives match for 'pytest'"""
486486
link = Link(url)
487487
search = Search(
488488
supplied=self.search_name,
489489
canonical=self.canonical_name,
490490
formats=['source', 'binary'],
491491
)
492-
result = self.evaluator._link_package_versions(link, search)
492+
result = self.evaluator.evaluate_link(link, search)
493493
expected = InstallationCandidate(self.search_name, self.version, link)
494494
assert result == expected, result
495495

@@ -502,15 +502,15 @@ def test_link_package_versions_match(self, url):
502502
'http:/yo/pytest_xdist-1.0-py2.py3-none-any.whl',
503503
],
504504
)
505-
def test_link_package_versions_substring_fails(self, url):
505+
def test_evaluate_link__substring_fails(self, url):
506506
"""Test that 'pytest<something> archives won't match for 'pytest'."""
507507
link = Link(url)
508508
search = Search(
509509
supplied=self.search_name,
510510
canonical=self.canonical_name,
511511
formats=['source', 'binary'],
512512
)
513-
result = self.evaluator._link_package_versions(link, search)
513+
result = self.evaluator.evaluate_link(link, search)
514514
assert result is None, result
515515

516516

0 commit comments

Comments
 (0)