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.
This commit is contained in:
Pradyun Gedam 2022-05-12 01:04:11 +01:00
parent 1d41abbb43
commit 611e9253ff
No known key found for this signature in database
GPG Key ID: FF99710C4332258E
2 changed files with 5 additions and 2 deletions

View File

@ -175,8 +175,10 @@ class BuildEnvironment:
) )
for req_str in reqs: for req_str in reqs:
req = Requirement(req_str) req = Requirement(req_str)
if req.marker is not None and not req.marker.evaluate(): # We're explicitly evaluating with an empty extra value, since build
continue # FIXME: Consider extras? # environments are not provided any mechanism to select specific extras.
if req.marker is not None and not req.marker.evaluate({"extra": ""}):
continue
dist = env.get_distribution(req.name) dist = env.get_distribution(req.name)
if not dist: if not dist:
missing.add(req_str) missing.add(req_str)

View File

@ -178,6 +178,7 @@ def test_build_env_requirements_check(script: PipTestEnvironment) -> None:
[ [
"bar==2.0; python_version < '3.0'", "bar==2.0; python_version < '3.0'",
"bar==3.0; python_version >= '3.0'", "bar==3.0; python_version >= '3.0'",
"foo==4.0; extra == 'dev'",
], ],
) )
assert r == (set(), set()), repr(r) assert r == (set(), set()), repr(r)