Skip to content

Commit f7c05a5

Browse files
committed
Allow pre-release to satisfy build requirements
1 parent cb24fb4 commit f7c05a5

File tree

3 files changed

+30
-2
lines changed

3 files changed

+30
-2
lines changed

news/11123.bugfix.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Allow using a pre-release version to satisfy a build requirement. This helps
2+
manually populated build environments to more accurately detect build-time
3+
requirement conflicts.

src/pip/_internal/build_env.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ def check_requirements(
185185
installed_req_str = f"{req.name}=={dist.version}"
186186
else:
187187
installed_req_str = f"{req.name}==={dist.version}"
188-
if dist.version not in req.specifier:
188+
if not req.specifier.contains(dist.version, prereleases=True):
189189
conflicting.add((installed_req_str, req_str))
190190
# FIXME: Consider direct URL?
191191
return conflicting, missing

tests/functional/test_pep517.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,13 @@
55

66
from pip._internal.build_env import BuildEnvironment
77
from pip._internal.req import InstallRequirement
8-
from tests.lib import PipTestEnvironment, TestData, make_test_finder, path_to_url
8+
from tests.lib import (
9+
PipTestEnvironment,
10+
TestData,
11+
create_basic_wheel_for_package,
12+
make_test_finder,
13+
path_to_url,
14+
)
915
from tests.lib.path import Path
1016

1117

@@ -210,6 +216,25 @@ def test_validate_conflicting_pep517_backend_requirements(
210216
assert result.returncode != 0 and msg in result.stderr, str(result)
211217

212218

219+
def test_pep517_backend_requirements_satisfied_by_prerelease(
220+
script: PipTestEnvironment,
221+
data: TestData,
222+
) -> None:
223+
create_basic_wheel_for_package(script, "myreq", "1.0a1")
224+
script.pip("install", "myreq==1.0a1", "--no-index", "-f", script.scratch_path)
225+
script.pip("install", "test_backend", "--no-index", "-f", data.backends)
226+
227+
project_dir = make_project(
228+
script.temp_path,
229+
requires=["test_backend", "myreq"],
230+
backend="test_backend",
231+
)
232+
project_dir.joinpath("backend_reqs.txt").write_text("myreq")
233+
234+
result = script.pip("install", "--no-index", "--no-build-isolation", project_dir)
235+
assert "Installing backend dependencies:" not in result.stdout
236+
237+
213238
def test_pep517_backend_requirements_already_satisfied(
214239
script: PipTestEnvironment, tmpdir: Path, data: TestData
215240
) -> None:

0 commit comments

Comments
 (0)