File tree 4 files changed +29
-1
lines changed 4 files changed +29
-1
lines changed Original file line number Diff line number Diff line change
1
+ Cache wheels built from Git requirements that are considered immutable,
2
+ because they point to a commit hash.
Original file line number Diff line number Diff line change @@ -59,6 +59,12 @@ class Git(VersionControl):
59
59
def get_base_rev_args (rev ):
60
60
return [rev ]
61
61
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
+
62
68
def get_git_version (self ):
63
69
VERSION_PFX = 'git version '
64
70
version = self .run_command (['version' ], show_stdout = False )
Original file line number Diff line number Diff line change @@ -319,6 +319,20 @@ def get_base_rev_args(rev):
319
319
"""
320
320
raise NotImplementedError
321
321
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
+
322
336
@classmethod
323
337
def make_rev_options (cls , rev = None , extra_args = None ):
324
338
# type: (Optional[str], Optional[CommandArgs]) -> RevOptions
Original file line number Diff line number Diff line change 34
34
)
35
35
from pip ._internal .locations import get_major_minor_version
36
36
from pip ._internal .models .link import Link
37
+ from pip ._internal .operations .prepare import _get_used_vcs_backend
37
38
from pip ._internal .utils .logging import indent_log
38
39
from pip ._internal .utils .marker_files import has_delete_marker_file
39
40
from pip ._internal .utils .misc import captured_stdout , ensure_dir , read_chunks
@@ -838,7 +839,12 @@ def should_cache(
838
839
return False
839
840
840
841
if req .link and req .link .is_vcs :
841
- # VCS checkout. Build wheel just for this run.
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 True
842
848
return False
843
849
844
850
link = req .link
You can’t perform that action at this time.
0 commit comments