Skip to content

Commit 46f51be

Browse files
committed
Treat deprecated aliases as equivalent in marker algebra
1 parent d3a9b27 commit 46f51be

File tree

3 files changed

+49
-52
lines changed

3 files changed

+49
-52
lines changed

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

+5-12
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

+11-40
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

+33
Original file line numberDiff line numberDiff line change
@@ -13638,3 +13638,36 @@ fn compile_derivation_chain() -> Result<()> {
1363813638

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

0 commit comments

Comments
 (0)