Skip to content

Commit bd3ae7b

Browse files
authored
Tests markers changing with required environments (#293)
Add a test case for astral-sh/uv#16824 (comment). Introduces `required-environments` to packse, with a basic passing `requires-python-subset` case.
1 parent 0b6f246 commit bd3ae7b

File tree

4 files changed

+56
-4
lines changed

4 files changed

+56
-4
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name = "markers-change-after-selection"
2+
description = '''A package is first used under a marker that is a subset of the required environments that it fulfills, and then under a marker that is a subset it doesn't fulfill.
3+
4+
`a` has a wheel only supports Windows, and the required platforms are Linux and Windows. The first time we encounter `a`, it's used with a Windows-only marker, so it doesn't violate. Afterwards, we select `b`, and while it doesn't change the version for `a`, it requires it universally. Now the resolution needs to fail, as `a` is now missing the Linux wheel.
5+
6+
See <https://github.com/astral-sh/uv/pull/16824#discussion_r2556176057>
7+
'''
8+
9+
[resolver_options]
10+
universal = true
11+
required_environments = ['sys_platform == "linux"', 'sys_platform == "win32"']
12+
13+
[root]
14+
requires = ["a; sys_platform == 'win32'", "b"]
15+
16+
[expected]
17+
satisfiable = false
18+
19+
[packages.a.versions."1.0.0"]
20+
sdist = false
21+
wheel_tags = ["cp312-abi3-win_amd64"]
22+
23+
[packages.b.versions."1.0.0"]
24+
requires = ["a; sys_platform == 'linux'"]
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
name = "requires-python-subset"
2+
description = "While both Linux and Windows are required and `win-only` has only a Windows wheel, `win-only` is also used only on Windows."
3+
4+
[resolver_options]
5+
universal = true
6+
required_environments = ['sys_platform == "linux"', 'sys_platform == "win32"']
7+
8+
[root]
9+
requires = ["win-only; sys_platform == 'win32'"]
10+
11+
[expected]
12+
satisfiable = true
13+
14+
[packages.win-only.versions."1.0.0"]
15+
sdist = false
16+
wheel_tags = ["cp312-abi3-win_amd64"]

src/packse/scenario.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,11 @@ class ResolverOptions(msgspec.Struct, forbid_unknown_fields=True):
143143
The Python platform to use for resolution.
144144
"""
145145

146+
required_environments: list[str] | None = None
147+
"""
148+
A list of required platforms, for packages that lack source distributions.
149+
"""
150+
146151
def hash(self) -> str:
147152
"""
148153
Return a hash of the contents
@@ -160,6 +165,9 @@ def hash(self) -> str:
160165
hasher.update(self.universal.to_bytes())
161166
if self.python_platform is not None:
162167
hasher.update(self.python_platform.encode())
168+
if self.required_environments is not None:
169+
for required_environment in self.required_environments:
170+
hasher.update(required_environment.encode())
163171

164172
return hasher.hexdigest()
165173

tests/__snapshots__/test_inspect.ambr

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,8 @@
115115
"no_build": [],
116116
"no_binary": [],
117117
"universal": false,
118-
"python_platform": null
118+
"python_platform": null,
119+
"required_environments": null
119120
},
120121
"template": "package",
121122
"description": "This is an example scenario, in which the user depends on a single package `a` which requires `b`.",
@@ -253,7 +254,8 @@
253254
"no_build": [],
254255
"no_binary": [],
255256
"universal": false,
256-
"python_platform": null
257+
"python_platform": null,
258+
"required_environments": null
257259
},
258260
"template": "package",
259261
"description": "This is an example scenario, in which the user depends on a single package `a` which requires `b`.",
@@ -418,7 +420,8 @@
418420
"no_build": [],
419421
"no_binary": [],
420422
"universal": false,
421-
"python_platform": null
423+
"python_platform": null,
424+
"required_environments": null
422425
},
423426
"template": "package",
424427
"description": "This is an example scenario written in TOML, in which the user depends on a single package `a` which requires `b`.",
@@ -556,7 +559,8 @@
556559
"no_build": [],
557560
"no_binary": [],
558561
"universal": false,
559-
"python_platform": null
562+
"python_platform": null,
563+
"required_environments": null
560564
},
561565
"template": "package",
562566
"description": "This is an example scenario written in YAML, in which the user depends on a single package `a` which requires `b`.",

0 commit comments

Comments
 (0)