From 611e9253ff74ca5b8ce438c2423373ab0d44c961 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Thu, 12 May 2022 01:04:11 +0100 Subject: [PATCH 1/2] 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. --- src/pip/_internal/build_env.py | 6 ++++-- tests/functional/test_build_env.py | 1 + 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/src/pip/_internal/build_env.py b/src/pip/_internal/build_env.py index 7783c9acda6..01165113b96 100644 --- a/src/pip/_internal/build_env.py +++ b/src/pip/_internal/build_env.py @@ -175,8 +175,10 @@ def check_requirements( ) for req_str in reqs: req = Requirement(req_str) - if req.marker is not None and not req.marker.evaluate(): - continue # FIXME: Consider extras? + # We're explicitly evaluating with an empty extra value, since build + # 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) if not dist: missing.add(req_str) diff --git a/tests/functional/test_build_env.py b/tests/functional/test_build_env.py index a7f89687c08..1b9f42d94c0 100644 --- a/tests/functional/test_build_env.py +++ b/tests/functional/test_build_env.py @@ -178,6 +178,7 @@ def test_build_env_requirements_check(script: PipTestEnvironment) -> None: [ "bar==2.0; python_version < '3.0'", "bar==3.0; python_version >= '3.0'", + "foo==4.0; extra == 'dev'", ], ) assert r == (set(), set()), repr(r) From bf090d37d18f27a60839063d02f607185a8d1164 Mon Sep 17 00:00:00 2001 From: Pradyun Gedam Date: Thu, 12 May 2022 21:22:21 +0100 Subject: [PATCH 2/2] :newspaper: --- news/11112.bugfix.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/11112.bugfix.rst diff --git a/news/11112.bugfix.rst b/news/11112.bugfix.rst new file mode 100644 index 00000000000..87b4b56a4d5 --- /dev/null +++ b/news/11112.bugfix.rst @@ -0,0 +1 @@ +Properly filter out optional dependencies (i.e. extras) when checking build environment distributions.