Skip to content

Commit 0e1e0ef

Browse files
sbidoulxavfernandez
authored andcommitted
_should_cache does not depend on check_binary_allowed
_should_cache is only called by _get_cache_dir. In pip install mode, _get_cache_dir is never called when check_binary_allowed returns False because in that case should_build_for_install_command has returned False before and the build was skipped. In pip wheel mode, check_binary_allowed always returns True (because it is not passed to the build function). So _should_cache can use _always_true for check_binary_allowed. *Alternative* Alternatively, we could have passed check_binary_allowed to build in pip wheel mode. The only difference is that wheels built locally from *legacy* packages would then not be cached, when pip wheel is used with --no-binary.
1 parent c55eee4 commit 0e1e0ef

File tree

3 files changed

+13
-48
lines changed

3 files changed

+13
-48
lines changed

src/pip/_internal/commands/install.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,6 @@ def run(self, options, args):
358358
wheel_cache=wheel_cache,
359359
build_options=[],
360360
global_options=[],
361-
check_binary_allowed=check_binary_allowed,
362361
)
363362

364363
# If we're using PEP 517, we cannot do a direct install

src/pip/_internal/wheel_builder.py

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ def should_build_for_install_command(
107107

108108
def _should_cache(
109109
req, # type: InstallRequirement
110-
check_binary_allowed, # type: BinaryAllowedPredicate
111110
):
112111
# type: (...) -> Optional[bool]
113112
"""
@@ -116,7 +115,7 @@ def _should_cache(
116115
has determined a wheel needs to be built.
117116
"""
118117
if not should_build_for_install_command(
119-
req, check_binary_allowed=check_binary_allowed
118+
req, check_binary_allowed=_always_true
120119
):
121120
# never cache if pip install would not have built
122121
# (editable mode, etc)
@@ -144,17 +143,13 @@ def _should_cache(
144143
def _get_cache_dir(
145144
req, # type: InstallRequirement
146145
wheel_cache, # type: WheelCache
147-
check_binary_allowed, # type: BinaryAllowedPredicate
148146
):
149147
# type: (...) -> str
150148
"""Return the persistent or temporary cache directory where the built
151149
wheel need to be stored.
152150
"""
153151
cache_available = bool(wheel_cache.cache_dir)
154-
if (
155-
cache_available and
156-
_should_cache(req, check_binary_allowed)
157-
):
152+
if cache_available and _should_cache(req):
158153
cache_dir = wheel_cache.get_path_for_link(req.link)
159154
else:
160155
cache_dir = wheel_cache.get_ephem_path_for_link(req.link)
@@ -263,18 +258,13 @@ def build(
263258
wheel_cache, # type: WheelCache
264259
build_options, # type: List[str]
265260
global_options, # type: List[str]
266-
check_binary_allowed=None, # type: Optional[BinaryAllowedPredicate]
267261
):
268262
# type: (...) -> BuildResult
269263
"""Build wheels.
270264
271265
:return: The list of InstallRequirement that succeeded to build and
272266
the list of InstallRequirement that failed to build.
273267
"""
274-
if check_binary_allowed is None:
275-
# Binaries allowed by default.
276-
check_binary_allowed = _always_true
277-
278268
if not requirements:
279269
return [], []
280270

@@ -287,9 +277,7 @@ def build(
287277
with indent_log():
288278
build_successes, build_failures = [], []
289279
for req in requirements:
290-
cache_dir = _get_cache_dir(
291-
req, wheel_cache, check_binary_allowed
292-
)
280+
cache_dir = _get_cache_dir(req, wheel_cache)
293281
wheel_file = _build_one(
294282
req, cache_dir, build_options, global_options
295283
)

tests/unit/test_wheel_builder.py

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -113,35 +113,17 @@ def test_should_build_legacy_wheel_installed(is_wheel_installed):
113113

114114

115115
@pytest.mark.parametrize(
116-
"req, disallow_binaries, expected",
116+
"req, expected",
117117
[
118-
(ReqMock(editable=True), False, False),
119-
(ReqMock(source_dir=None), False, False),
120-
(ReqMock(link=Link("git+https://g.c/org/repo")), False, False),
121-
(ReqMock(link=Link("https://g.c/dist.tgz")), False, False),
122-
(ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), False, True),
123-
(ReqMock(editable=True), True, False),
124-
(ReqMock(source_dir=None), True, False),
125-
(ReqMock(link=Link("git+https://g.c/org/repo")), True, False),
126-
(ReqMock(link=Link("https://g.c/dist.tgz")), True, False),
127-
(ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), True, False),
118+
(ReqMock(editable=True), False),
119+
(ReqMock(source_dir=None), False),
120+
(ReqMock(link=Link("git+https://g.c/org/repo")), False),
121+
(ReqMock(link=Link("https://g.c/dist.tgz")), False),
122+
(ReqMock(link=Link("https://g.c/dist-2.0.4.tgz")), True),
128123
],
129124
)
130-
def test_should_cache(
131-
req, disallow_binaries, expected
132-
):
133-
def check_binary_allowed(req):
134-
return not disallow_binaries
135-
136-
should_cache = wheel_builder._should_cache(
137-
req, check_binary_allowed
138-
)
139-
if not wheel_builder.should_build_for_install_command(
140-
req, check_binary_allowed=check_binary_allowed
141-
):
142-
# never cache if pip install would not have built)
143-
assert not should_cache
144-
assert should_cache is expected
125+
def test_should_cache(req, expected):
126+
assert wheel_builder._should_cache(req) is expected
145127

146128

147129
def test_should_cache_git_sha(script, tmpdir):
@@ -153,16 +135,12 @@ def test_should_cache_git_sha(script, tmpdir):
153135
# a link referencing a sha should be cached
154136
url = "git+https://g.c/o/r@" + commit + "#egg=mypkg"
155137
req = ReqMock(link=Link(url), source_dir=repo_path)
156-
assert wheel_builder._should_cache(
157-
req, check_binary_allowed=lambda r: True,
158-
)
138+
assert wheel_builder._should_cache(req)
159139

160140
# a link not referencing a sha should not be cached
161141
url = "git+https://g.c/o/r@master#egg=mypkg"
162142
req = ReqMock(link=Link(url), source_dir=repo_path)
163-
assert not wheel_builder._should_cache(
164-
req, check_binary_allowed=lambda r: True,
165-
)
143+
assert not wheel_builder._should_cache(req)
166144

167145

168146
def test_format_command_result__INFO(caplog):

0 commit comments

Comments
 (0)