Skip to content

Commit

Permalink
Optimize upgrade of already-satisfied pinned requirement
Browse files Browse the repository at this point in the history
Example: after installing six 1.12.0, `pip install -Uv six==1.12.0`
now returns immediately, instead of going to the index to check for a
version that can’t possibly be considered better.

This optimization is most significant when upgrading via a
requirements file with many pinned versions and some non-pinned
versions.

Signed-off-by: Anders Kaseorg <andersk@mit.edu>
  • Loading branch information
andersk committed Oct 3, 2019
1 parent e6f69fa commit 25a003f
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/pip/_internal/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -874,10 +874,15 @@ def find_requirement(self, req, upgrade):
Returns a Link if found,
Raises DistributionNotFound or BestVersionAlreadyInstalled otherwise
"""
hashes = req.hashes(trust_internet=False)
best_candidate_result = self.find_best_candidate(
req.name, specifier=req.specifier, hashes=hashes,
)
if req.is_pinned and req.satisfied_by is not None:
# Pinned version is already satisfied; no need to check
# the index for a better version.
best_candidate_result = BestCandidateResult([], [], None)
else:
hashes = req.hashes(trust_internet=False)
best_candidate_result = self.find_best_candidate(
req.name, specifier=req.specifier, hashes=hashes,
)
best_candidate = best_candidate_result.best_candidate

installed_version = None # type: Optional[_BaseVersion]
Expand Down

0 comments on commit 25a003f

Please sign in to comment.