Skip to content

Commit 7607c14

Browse files
authored
Merge pull request #11370 from sbidoul/clarify-should-build-sbi
Clarify should_build()
2 parents 08087ba + d8e2d66 commit 7607c14

File tree

3 files changed

+21
-20
lines changed

3 files changed

+21
-20
lines changed

src/pip/_internal/commands/install.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,15 +45,17 @@
4545
virtualenv_no_global,
4646
)
4747
from pip._internal.wheel_builder import (
48-
BinaryAllowedPredicate,
48+
BdistWheelAllowedPredicate,
4949
build,
5050
should_build_for_install_command,
5151
)
5252

5353
logger = getLogger(__name__)
5454

5555

56-
def get_check_binary_allowed(format_control: FormatControl) -> BinaryAllowedPredicate:
56+
def get_check_bdist_wheel_allowed(
57+
format_control: FormatControl,
58+
) -> BdistWheelAllowedPredicate:
5759
def check_binary_allowed(req: InstallRequirement) -> bool:
5860
canonical_name = canonicalize_name(req.name or "")
5961
allowed_formats = format_control.get_allowed_formats(canonical_name)
@@ -409,12 +411,14 @@ def run(self, options: Values, args: List[str]) -> int:
409411
modifying_pip = pip_req.satisfied_by is None
410412
protect_pip_from_modification_on_windows(modifying_pip=modifying_pip)
411413

412-
check_binary_allowed = get_check_binary_allowed(finder.format_control)
414+
check_bdist_wheel_allowed = get_check_bdist_wheel_allowed(
415+
finder.format_control
416+
)
413417

414418
reqs_to_build = [
415419
r
416420
for r in requirement_set.requirements.values()
417-
if should_build_for_install_command(r, check_binary_allowed)
421+
if should_build_for_install_command(r, check_bdist_wheel_allowed)
418422
]
419423

420424
_, build_failures = build(

src/pip/_internal/wheel_builder.py

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import os.path
66
import re
77
import shutil
8-
from typing import Any, Callable, Iterable, List, Optional, Tuple
8+
from typing import Callable, Iterable, List, Optional, Tuple
99

1010
from pip._vendor.packaging.utils import canonicalize_name, canonicalize_version
1111
from pip._vendor.packaging.version import InvalidVersion, Version
@@ -32,7 +32,7 @@
3232

3333
_egg_info_re = re.compile(r"([a-z0-9_.]+)-([a-z0-9_.!+-]+)", re.IGNORECASE)
3434

35-
BinaryAllowedPredicate = Callable[[InstallRequirement], bool]
35+
BdistWheelAllowedPredicate = Callable[[InstallRequirement], bool]
3636
BuildResult = Tuple[List[InstallRequirement], List[InstallRequirement]]
3737

3838

@@ -47,7 +47,7 @@ def _contains_egg_info(s: str) -> bool:
4747
def _should_build(
4848
req: InstallRequirement,
4949
need_wheel: bool,
50-
check_binary_allowed: BinaryAllowedPredicate,
50+
check_bdist_wheel: Optional[BdistWheelAllowedPredicate] = None,
5151
) -> bool:
5252
"""Return whether an InstallRequirement should be built into a wheel."""
5353
if req.constraint:
@@ -78,7 +78,8 @@ def _should_build(
7878
if req.use_pep517:
7979
return True
8080

81-
if not check_binary_allowed(req):
81+
assert check_bdist_wheel is not None
82+
if not check_bdist_wheel(req):
8283
logger.info(
8384
"Skipping wheel build for %s, due to binaries being disabled for it.",
8485
req.name,
@@ -96,15 +97,15 @@ def _should_build(
9697
def should_build_for_wheel_command(
9798
req: InstallRequirement,
9899
) -> bool:
99-
return _should_build(req, need_wheel=True, check_binary_allowed=_always_true)
100+
return _should_build(req, need_wheel=True)
100101

101102

102103
def should_build_for_install_command(
103104
req: InstallRequirement,
104-
check_binary_allowed: BinaryAllowedPredicate,
105+
check_bdist_wheel_allowed: BdistWheelAllowedPredicate,
105106
) -> bool:
106107
return _should_build(
107-
req, need_wheel=False, check_binary_allowed=check_binary_allowed
108+
req, need_wheel=False, check_bdist_wheel=check_bdist_wheel_allowed
108109
)
109110

110111

@@ -156,10 +157,6 @@ def _get_cache_dir(
156157
return cache_dir
157158

158159

159-
def _always_true(_: Any) -> bool:
160-
return True
161-
162-
163160
def _verify_one(req: InstallRequirement, wheel_path: str) -> None:
164161
canonical_name = canonicalize_name(req.name or "")
165162
w = Wheel(os.path.basename(wheel_path))

tests/unit/test_wheel_builder.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ def supports_pyproject_editable(self) -> bool:
5858

5959

6060
@pytest.mark.parametrize(
61-
"req, disallow_binaries, expected",
61+
"req, disallow_bdist_wheel, expected",
6262
[
6363
# When binaries are allowed, we build.
6464
(ReqMock(use_pep517=True), False, True),
@@ -110,11 +110,11 @@ def supports_pyproject_editable(self) -> bool:
110110
],
111111
)
112112
def test_should_build_for_install_command(
113-
req: ReqMock, disallow_binaries: bool, expected: bool
113+
req: ReqMock, disallow_bdist_wheel: bool, expected: bool
114114
) -> None:
115115
should_build = wheel_builder.should_build_for_install_command(
116116
cast(InstallRequirement, req),
117-
check_binary_allowed=lambda req: not disallow_binaries,
117+
check_bdist_wheel_allowed=lambda req: not disallow_bdist_wheel,
118118
)
119119
assert should_build is expected
120120

@@ -144,7 +144,7 @@ def test_should_build_legacy_wheel_not_installed(is_wheel_installed: mock.Mock)
144144
legacy_req = ReqMock(use_pep517=False)
145145
should_build = wheel_builder.should_build_for_install_command(
146146
cast(InstallRequirement, legacy_req),
147-
check_binary_allowed=lambda req: True,
147+
check_bdist_wheel_allowed=lambda req: True,
148148
)
149149
assert not should_build
150150

@@ -155,7 +155,7 @@ def test_should_build_legacy_wheel_installed(is_wheel_installed: mock.Mock) -> N
155155
legacy_req = ReqMock(use_pep517=False)
156156
should_build = wheel_builder.should_build_for_install_command(
157157
cast(InstallRequirement, legacy_req),
158-
check_binary_allowed=lambda req: True,
158+
check_bdist_wheel_allowed=lambda req: True,
159159
)
160160
assert should_build
161161

0 commit comments

Comments
 (0)