Skip to content

Commit df844e1

Browse files
Treat deprecated aliases as equivalent in marker algebra (#9342)
## Summary This PR modifies our lowered representation such that any deprecated aliases are treated as "the same" marker in the algebra. So, for example, we now recognize that this is impossible, despite the marker names being different: ``` typing-extensions ; platform.python_implementation == 'CPython' and python_implementation != 'CPython' ``` Similarly, we now recognize that this is just `sys_platform == 'win32'`, despite the presence of both markers: ``` anyio ; sys_platform == 'win32' and sys.platform == 'win32' ```
1 parent 1068630 commit df844e1

3 files changed

Lines changed: 49 additions & 52 deletions

File tree

crates/uv-pep508/src/marker/environment.rs

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -47,22 +47,15 @@ impl MarkerEnvironment {
4747
pub fn get_string(&self, key: LoweredMarkerValueString) -> &str {
4848
match key {
4949
LoweredMarkerValueString::ImplementationName => self.implementation_name(),
50-
LoweredMarkerValueString::OsName | LoweredMarkerValueString::OsNameDeprecated => {
51-
self.os_name()
52-
}
53-
LoweredMarkerValueString::PlatformMachine
54-
| LoweredMarkerValueString::PlatformMachineDeprecated => self.platform_machine(),
55-
LoweredMarkerValueString::PlatformPythonImplementation
56-
| LoweredMarkerValueString::PlatformPythonImplementationDeprecated
57-
| LoweredMarkerValueString::PythonImplementationDeprecated => {
50+
LoweredMarkerValueString::OsName => self.os_name(),
51+
LoweredMarkerValueString::PlatformMachine => self.platform_machine(),
52+
LoweredMarkerValueString::PlatformPythonImplementation => {
5853
self.platform_python_implementation()
5954
}
6055
LoweredMarkerValueString::PlatformRelease => self.platform_release(),
6156
LoweredMarkerValueString::PlatformSystem => self.platform_system(),
62-
LoweredMarkerValueString::PlatformVersion
63-
| LoweredMarkerValueString::PlatformVersionDeprecated => self.platform_version(),
64-
LoweredMarkerValueString::SysPlatform
65-
| LoweredMarkerValueString::SysPlatformDeprecated => self.sys_platform(),
57+
LoweredMarkerValueString::PlatformVersion => self.platform_version(),
58+
LoweredMarkerValueString::SysPlatform => self.sys_platform(),
6659
}
6760
}
6861
}

crates/uv-pep508/src/marker/lowering.rs

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -53,53 +53,40 @@ pub enum LoweredMarkerValueString {
5353
ImplementationName,
5454
/// `os_name`
5555
OsName,
56-
/// Deprecated `os.name` from <https://peps.python.org/pep-0345/#environment-markers>
57-
OsNameDeprecated,
5856
/// `platform_machine`
5957
PlatformMachine,
6058
/// Deprecated `platform.machine` from <https://peps.python.org/pep-0345/#environment-markers>
61-
PlatformMachineDeprecated,
6259
/// `platform_python_implementation`
6360
PlatformPythonImplementation,
64-
/// Deprecated `platform.python_implementation` from <https://peps.python.org/pep-0345/#environment-markers>
65-
PlatformPythonImplementationDeprecated,
66-
/// Deprecated `python_implementation` from <https://github.com/pypa/packaging/issues/72>
67-
PythonImplementationDeprecated,
6861
/// `platform_release`
6962
PlatformRelease,
7063
/// `platform_system`
7164
PlatformSystem,
7265
/// `platform_version`
7366
PlatformVersion,
74-
/// Deprecated `platform.version` from <https://peps.python.org/pep-0345/#environment-markers>
75-
PlatformVersionDeprecated,
7667
/// `sys_platform`
7768
SysPlatform,
78-
/// Deprecated `sys.platform` from <https://peps.python.org/pep-0345/#environment-markers>
79-
SysPlatformDeprecated,
8069
}
8170

8271
impl From<MarkerValueString> for LoweredMarkerValueString {
8372
fn from(value: MarkerValueString) -> Self {
8473
match value {
8574
MarkerValueString::ImplementationName => Self::ImplementationName,
8675
MarkerValueString::OsName => Self::OsName,
87-
MarkerValueString::OsNameDeprecated => Self::OsNameDeprecated,
76+
MarkerValueString::OsNameDeprecated => Self::OsName,
8877
MarkerValueString::PlatformMachine => Self::PlatformMachine,
89-
MarkerValueString::PlatformMachineDeprecated => Self::PlatformMachineDeprecated,
78+
MarkerValueString::PlatformMachineDeprecated => Self::PlatformMachine,
9079
MarkerValueString::PlatformPythonImplementation => Self::PlatformPythonImplementation,
9180
MarkerValueString::PlatformPythonImplementationDeprecated => {
92-
Self::PlatformPythonImplementationDeprecated
93-
}
94-
MarkerValueString::PythonImplementationDeprecated => {
95-
Self::PythonImplementationDeprecated
81+
Self::PlatformPythonImplementation
9682
}
83+
MarkerValueString::PythonImplementationDeprecated => Self::PlatformPythonImplementation,
9784
MarkerValueString::PlatformRelease => Self::PlatformRelease,
9885
MarkerValueString::PlatformSystem => Self::PlatformSystem,
9986
MarkerValueString::PlatformVersion => Self::PlatformVersion,
100-
MarkerValueString::PlatformVersionDeprecated => Self::PlatformVersionDeprecated,
87+
MarkerValueString::PlatformVersionDeprecated => Self::PlatformVersion,
10188
MarkerValueString::SysPlatform => Self::SysPlatform,
102-
MarkerValueString::SysPlatformDeprecated => Self::SysPlatformDeprecated,
89+
MarkerValueString::SysPlatformDeprecated => Self::SysPlatform,
10390
}
10491
}
10592
}
@@ -109,24 +96,14 @@ impl From<LoweredMarkerValueString> for MarkerValueString {
10996
match value {
11097
LoweredMarkerValueString::ImplementationName => Self::ImplementationName,
11198
LoweredMarkerValueString::OsName => Self::OsName,
112-
LoweredMarkerValueString::OsNameDeprecated => Self::OsNameDeprecated,
11399
LoweredMarkerValueString::PlatformMachine => Self::PlatformMachine,
114-
LoweredMarkerValueString::PlatformMachineDeprecated => Self::PlatformMachineDeprecated,
115100
LoweredMarkerValueString::PlatformPythonImplementation => {
116101
Self::PlatformPythonImplementation
117102
}
118-
LoweredMarkerValueString::PlatformPythonImplementationDeprecated => {
119-
Self::PlatformPythonImplementationDeprecated
120-
}
121-
LoweredMarkerValueString::PythonImplementationDeprecated => {
122-
Self::PythonImplementationDeprecated
123-
}
124103
LoweredMarkerValueString::PlatformRelease => Self::PlatformRelease,
125104
LoweredMarkerValueString::PlatformSystem => Self::PlatformSystem,
126105
LoweredMarkerValueString::PlatformVersion => Self::PlatformVersion,
127-
LoweredMarkerValueString::PlatformVersionDeprecated => Self::PlatformVersionDeprecated,
128106
LoweredMarkerValueString::SysPlatform => Self::SysPlatform,
129-
LoweredMarkerValueString::SysPlatformDeprecated => Self::SysPlatformDeprecated,
130107
}
131108
}
132109
}
@@ -136,19 +113,13 @@ impl Display for LoweredMarkerValueString {
136113
fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
137114
match self {
138115
Self::ImplementationName => f.write_str("implementation_name"),
139-
Self::OsName | Self::OsNameDeprecated => f.write_str("os_name"),
140-
Self::PlatformMachine | Self::PlatformMachineDeprecated => {
141-
f.write_str("platform_machine")
142-
}
143-
Self::PlatformPythonImplementation
144-
| Self::PlatformPythonImplementationDeprecated
145-
| Self::PythonImplementationDeprecated => f.write_str("platform_python_implementation"),
116+
Self::OsName => f.write_str("os_name"),
117+
Self::PlatformMachine => f.write_str("platform_machine"),
118+
Self::PlatformPythonImplementation => f.write_str("platform_python_implementation"),
146119
Self::PlatformRelease => f.write_str("platform_release"),
147120
Self::PlatformSystem => f.write_str("platform_system"),
148-
Self::PlatformVersion | Self::PlatformVersionDeprecated => {
149-
f.write_str("platform_version")
150-
}
151-
Self::SysPlatform | Self::SysPlatformDeprecated => f.write_str("sys_platform"),
121+
Self::PlatformVersion => f.write_str("platform_version"),
122+
Self::SysPlatform => f.write_str("sys_platform"),
152123
}
153124
}
154125
}

crates/uv/tests/it/pip_compile.rs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13626,3 +13626,36 @@ fn compile_derivation_chain() -> Result<()> {
1362613626

1362713627
Ok(())
1362813628
}
13629+
13630+
/// Treat `sys_platform` and `sys.platform` as equivalent markers in the marker algebra.
13631+
#[test]
13632+
fn universal_disjoint_deprecated_markers() -> Result<()> {
13633+
let context = TestContext::new("3.12");
13634+
let requirements_in = context.temp_dir.child("requirements.in");
13635+
requirements_in.write_str(indoc::indoc! {r"
13636+
anyio ; sys_platform == 'win32' and sys.platform == 'win32'
13637+
typing-extensions ; platform.python_implementation == 'CPython' and python_implementation != 'CPython'
13638+
"})?;
13639+
13640+
uv_snapshot!(context.filters(), context.pip_compile()
13641+
.arg("requirements.in")
13642+
.arg("--universal"), @r###"
13643+
success: true
13644+
exit_code: 0
13645+
----- stdout -----
13646+
# This file was autogenerated by uv via the following command:
13647+
# uv pip compile --cache-dir [CACHE_DIR] requirements.in --universal
13648+
anyio==4.3.0 ; sys_platform == 'win32'
13649+
# via -r requirements.in
13650+
idna==3.6 ; sys_platform == 'win32'
13651+
# via anyio
13652+
sniffio==1.3.1 ; sys_platform == 'win32'
13653+
# via anyio
13654+
13655+
----- stderr -----
13656+
Resolved 3 packages in [TIME]
13657+
"###
13658+
);
13659+
13660+
Ok(())
13661+
}

0 commit comments

Comments
 (0)