Skip to content

Commit f20ab57

Browse files
authored
Merge pull request #11124 from uranusjr/use-contain-for-checking
Allow pre-release to satisfy build requirements
2 parents 30af807 + f7c05a5 commit f20ab57

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
@@ -187,7 +187,7 @@ def check_requirements(
187187
installed_req_str = f"{req.name}=={dist.version}"
188188
else:
189189
installed_req_str = f"{req.name}==={dist.version}"
190-
if dist.version not in req.specifier:
190+
if not req.specifier.contains(dist.version, prereleases=True):
191191
conflicting.add((installed_req_str, req_str))
192192
# FIXME: Consider direct URL?
193193
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

@@ -232,6 +238,25 @@ def test_validate_conflicting_pep517_backend_requirements(
232238
assert result.returncode != 0 and msg in result.stderr, str(result)
233239

234240

241+
def test_pep517_backend_requirements_satisfied_by_prerelease(
242+
script: PipTestEnvironment,
243+
data: TestData,
244+
) -> None:
245+
create_basic_wheel_for_package(script, "myreq", "1.0a1")
246+
script.pip("install", "myreq==1.0a1", "--no-index", "-f", script.scratch_path)
247+
script.pip("install", "test_backend", "--no-index", "-f", data.backends)
248+
249+
project_dir = make_project(
250+
script.temp_path,
251+
requires=["test_backend", "myreq"],
252+
backend="test_backend",
253+
)
254+
project_dir.joinpath("backend_reqs.txt").write_text("myreq")
255+
256+
result = script.pip("install", "--no-index", "--no-build-isolation", project_dir)
257+
assert "Installing backend dependencies:" not in result.stdout
258+
259+
235260
def test_pep517_backend_requirements_already_satisfied(
236261
script: PipTestEnvironment, tmpdir: Path, data: TestData
237262
) -> None:

0 commit comments

Comments
 (0)