Skip to content

Commit 611e925

Browse files
committed
Filter out build requirements that require an extra to be used
There is no mechanism provided for build requirements to have extras. It should be acceptable to enforce that any "optional" packages that are supposed to be conditionally installed based on the presence of an extra should not be installed in a build environment.
1 parent 1d41abb commit 611e925

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

src/pip/_internal/build_env.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,10 @@ def check_requirements(
175175
)
176176
for req_str in reqs:
177177
req = Requirement(req_str)
178-
if req.marker is not None and not req.marker.evaluate():
179-
continue # FIXME: Consider extras?
178+
# We're explicitly evaluating with an empty extra value, since build
179+
# environments are not provided any mechanism to select specific extras.
180+
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
181+
continue
180182
dist = env.get_distribution(req.name)
181183
if not dist:
182184
missing.add(req_str)

tests/functional/test_build_env.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ def test_build_env_requirements_check(script: PipTestEnvironment) -> None:
178178
[
179179
"bar==2.0; python_version < '3.0'",
180180
"bar==3.0; python_version >= '3.0'",
181+
"foo==4.0; extra == 'dev'",
181182
],
182183
)
183184
assert r == (set(), set()), repr(r)

0 commit comments

Comments
 (0)