Skip to content

Commit 3894987

Browse files
committed
Cache wheels built from immutable Git requirements
Cache wheels that are built from Git requirements that contain an immutable revision (i.e. a sha).
1 parent 2a2794e commit 3894987

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

news/6640.feature

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Cache wheels built from Git requirements that are considered immutable,
2+
because they point to a commit hash.

src/pip/_internal/vcs/git.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ class Git(VersionControl):
5959
def get_base_rev_args(rev):
6060
return [rev]
6161

62+
def is_immutable_rev_checkout(self, url, dest):
63+
_, rev_options = self.get_url_rev_options(url)
64+
if not rev_options.rev:
65+
return False
66+
return self.is_commit_id_equal(dest, rev_options.rev)
67+
6268
def get_git_version(self):
6369
VERSION_PFX = 'git version '
6470
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
@@ -319,6 +319,20 @@ def get_base_rev_args(rev):
319319
"""
320320
raise NotImplementedError
321321

322+
def is_immutable_rev_checkout(self, url, dest):
323+
# type: (str, str) -> bool
324+
"""
325+
Return true if the commit hash checked out at dest matches
326+
the revision in url.
327+
328+
Always return False, if the VCS does not support immutable commit
329+
hashes.
330+
331+
This method does not check if there are local uncommitted changes
332+
in dest after checkout, as pip currently has no use case for that.
333+
"""
334+
return False
335+
322336
@classmethod
323337
def make_rev_options(cls, rev=None, extra_args=None):
324338
# type: (Optional[str], Optional[CommandArgs]) -> RevOptions

src/pip/_internal/wheel.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
)
3535
from pip._internal.locations import get_major_minor_version
3636
from pip._internal.models.link import Link
37+
from pip._internal.operations.prepare import _get_used_vcs_backend
3738
from pip._internal.utils.logging import indent_log
3839
from pip._internal.utils.marker_files import has_delete_marker_file
3940
from pip._internal.utils.misc import captured_stdout, ensure_dir, read_chunks
@@ -838,8 +839,13 @@ def should_cache(
838839
return False
839840

840841
if req.link and req.link.is_vcs:
841-
# VCS checkout. Build wheel just for this run.
842-
return False
842+
# VCS checkout. Build wheel just for this run
843+
# unless it points to an immutable commit hash in which
844+
# case it can be cached.
845+
vcs_backend = _get_used_vcs_backend(req.link)
846+
if vcs_backend.is_immutable_rev_checkout(req.link.url, req.source_dir):
847+
return False
848+
return True
843849

844850
link = req.link
845851
base, ext = link.splitext()

0 commit comments

Comments
 (0)