Skip to content

Commit f8096a5

Browse files
committed
Cache wheels built from immutable VCS requirements
Cache wheels that are built from VCS requirements that contain an immutable revision (such as a git sha).
1 parent 0f9c2e6 commit f8096a5

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

news/6640.feature

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Cache wheels built from VCS requirements that are considered immutables

src/pip/_internal/vcs/git.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,12 @@ class Git(VersionControl):
4848
def get_base_rev_args(rev):
4949
return [rev]
5050

51+
def is_immutable_rev_checkout(self, url, dest):
52+
_, rev_options = self.get_url_rev_options(url)
53+
if not rev_options.rev:
54+
return False
55+
return self.is_commit_id_equal(dest, rev_options.rev)
56+
5157
def get_git_version(self):
5258
VERSION_PFX = 'git version '
5359
version = self.run_command(['version'], show_stdout=False)

src/pip/_internal/vcs/versioncontrol.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,20 @@ def get_base_rev_args(rev):
268268
"""
269269
raise NotImplementedError
270270

271+
def is_immutable_rev_checkout(self, url, dest):
272+
# type: (str, str) -> bool
273+
"""
274+
Return true if the commit hash checked out at dest matches
275+
the revision in url.
276+
277+
Always return False, if the VCS does not support immutable commit
278+
hashes.
279+
280+
This method does not check if there are local uncommitted changes
281+
in dest after checkout, as pip currently has no use case for that.
282+
"""
283+
return False
284+
271285
@classmethod
272286
def make_rev_options(cls, rev=None, extra_args=None):
273287
# type: (Optional[str], Optional[List[str]]) -> RevOptions

src/pip/_internal/wheel.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
from pip._vendor.six import StringIO
2828

2929
from pip._internal import pep425tags
30-
from pip._internal.download import unpack_file_url
30+
from pip._internal.download import _get_used_vcs_backend, unpack_file_url
3131
from pip._internal.exceptions import (
3232
InstallationError,
3333
InvalidWheelFilename,
@@ -845,7 +845,9 @@ def should_use_ephemeral_cache(
845845
# VCS checkout. Build wheel just for this run
846846
# unless it points to an immutable commit hash in which
847847
# case it can be cached.
848-
# TODO if req.link.is_vcs_immutable: return False
848+
vcs_backend = _get_used_vcs_backend(req.link)
849+
if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
850+
return False
849851
return True
850852

851853
link = req.link

0 commit comments

Comments
 (0)