Skip to content

Commit ae2d221

Browse files
authored
Merge pull request #13232 from sbidoul/ref-should-build
Simplify _should_build
2 parents 331400c + 5b20593 commit ae2d221

File tree

3 files changed

+6
-50
lines changed

3 files changed

+6
-50
lines changed

src/pip/_internal/commands/wheel.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
)
1717
from pip._internal.utils.misc import ensure_dir, normalize_path
1818
from pip._internal.utils.temp_dir import TempDirectory
19-
from pip._internal.wheel_builder import build, should_build_for_wheel_command
19+
from pip._internal.wheel_builder import build
2020

2121
logger = logging.getLogger(__name__)
2222

@@ -150,7 +150,7 @@ def run(self, options: Values, args: List[str]) -> int:
150150
for req in requirement_set.requirements.values():
151151
if req.is_wheel:
152152
preparer.save_linked_requirement(req)
153-
elif should_build_for_wheel_command(req):
153+
else:
154154
reqs_to_build.append(req)
155155

156156
preparer.prepare_linked_requirements_more(requirement_set.requirements.values())

src/pip/_internal/wheel_builder.py

+4-25
Original file line numberDiff line numberDiff line change
@@ -43,29 +43,14 @@ def _contains_egg_info(s: str) -> bool:
4343

4444
def _should_build(
4545
req: InstallRequirement,
46-
need_wheel: bool,
4746
) -> bool:
4847
"""Return whether an InstallRequirement should be built into a wheel."""
49-
if req.constraint:
50-
# never build requirements that are merely constraints
51-
return False
48+
assert not req.constraint
49+
5250
if req.is_wheel:
53-
if need_wheel:
54-
logger.info(
55-
"Skipping %s, due to already being wheel.",
56-
req.name,
57-
)
5851
return False
5952

60-
if need_wheel:
61-
# i.e. pip wheel, not pip install
62-
return True
63-
64-
# From this point, this concerns the pip install command only
65-
# (need_wheel=False).
66-
67-
if not req.source_dir:
68-
return False
53+
assert req.source_dir
6954

7055
if req.editable:
7156
# we only build PEP 660 editable requirements
@@ -74,16 +59,10 @@ def _should_build(
7459
return True
7560

7661

77-
def should_build_for_wheel_command(
78-
req: InstallRequirement,
79-
) -> bool:
80-
return _should_build(req, need_wheel=True)
81-
82-
8362
def should_build_for_install_command(
8463
req: InstallRequirement,
8564
) -> bool:
86-
return _should_build(req, need_wheel=False)
65+
return _should_build(req)
8766

8867

8968
def _should_cache(

tests/unit/test_wheel_builder.py

-23
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,6 @@ class ReqMock:
5151
# We build, whether pep 517 is enabled or not.
5252
(ReqMock(use_pep517=True), True),
5353
(ReqMock(use_pep517=False), True),
54-
# We don't build constraints.
55-
(ReqMock(constraint=True), False),
5654
# We don't build reqs that are already wheels.
5755
(ReqMock(is_wheel=True), False),
5856
# We build editables if the backend supports PEP 660.
@@ -65,8 +63,6 @@ class ReqMock:
6563
ReqMock(editable=True, use_pep517=True, supports_pyproject_editable=False),
6664
False,
6765
),
68-
# We don't build if there is no source dir (whatever that means!).
69-
(ReqMock(source_dir=None), False),
7066
# By default (i.e. when binaries are allowed), VCS requirements
7167
# should be built in install mode.
7268
(
@@ -86,25 +82,6 @@ def test_should_build_for_install_command(req: ReqMock, expected: bool) -> None:
8682
assert should_build is expected
8783

8884

89-
@pytest.mark.parametrize(
90-
"req, expected",
91-
[
92-
(ReqMock(), True),
93-
(ReqMock(constraint=True), False),
94-
(ReqMock(is_wheel=True), False),
95-
(ReqMock(editable=True, use_pep517=False), True),
96-
(ReqMock(editable=True, use_pep517=True), True),
97-
(ReqMock(source_dir=None), True),
98-
(ReqMock(link=Link("git+https://g.c/org/repo")), True),
99-
],
100-
)
101-
def test_should_build_for_wheel_command(req: ReqMock, expected: bool) -> None:
102-
should_build = wheel_builder.should_build_for_wheel_command(
103-
cast(InstallRequirement, req)
104-
)
105-
assert should_build is expected
106-
107-
10885
@pytest.mark.parametrize(
10986
"req, expected",
11087
[

0 commit comments

Comments
 (0)