From df844e1ec95f87115b6603b11d7ccf87853c00c9 Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Tue, 26 Nov 2024 09:27:24 -0500 Subject: [PATCH] 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' ``` --- crates/uv-pep508/src/marker/environment.rs | 17 +++----- crates/uv-pep508/src/marker/lowering.rs | 51 +++++----------------- crates/uv/tests/it/pip_compile.rs | 33 ++++++++++++++ 3 files changed, 49 insertions(+), 52 deletions(-) diff --git a/crates/uv-pep508/src/marker/environment.rs b/crates/uv-pep508/src/marker/environment.rs index de0fbe8fff64..5ae1d5fc390f 100644 --- a/crates/uv-pep508/src/marker/environment.rs +++ b/crates/uv-pep508/src/marker/environment.rs @@ -47,22 +47,15 @@ impl MarkerEnvironment { pub fn get_string(&self, key: LoweredMarkerValueString) -> &str { match key { LoweredMarkerValueString::ImplementationName => self.implementation_name(), - LoweredMarkerValueString::OsName | LoweredMarkerValueString::OsNameDeprecated => { - self.os_name() - } - LoweredMarkerValueString::PlatformMachine - | LoweredMarkerValueString::PlatformMachineDeprecated => self.platform_machine(), - LoweredMarkerValueString::PlatformPythonImplementation - | LoweredMarkerValueString::PlatformPythonImplementationDeprecated - | LoweredMarkerValueString::PythonImplementationDeprecated => { + LoweredMarkerValueString::OsName => self.os_name(), + LoweredMarkerValueString::PlatformMachine => self.platform_machine(), + LoweredMarkerValueString::PlatformPythonImplementation => { self.platform_python_implementation() } LoweredMarkerValueString::PlatformRelease => self.platform_release(), LoweredMarkerValueString::PlatformSystem => self.platform_system(), - LoweredMarkerValueString::PlatformVersion - | LoweredMarkerValueString::PlatformVersionDeprecated => self.platform_version(), - LoweredMarkerValueString::SysPlatform - | LoweredMarkerValueString::SysPlatformDeprecated => self.sys_platform(), + LoweredMarkerValueString::PlatformVersion => self.platform_version(), + LoweredMarkerValueString::SysPlatform => self.sys_platform(), } } } diff --git a/crates/uv-pep508/src/marker/lowering.rs b/crates/uv-pep508/src/marker/lowering.rs index 056135278019..c4677cd1387a 100644 --- a/crates/uv-pep508/src/marker/lowering.rs +++ b/crates/uv-pep508/src/marker/lowering.rs @@ -53,30 +53,19 @@ pub enum LoweredMarkerValueString { ImplementationName, /// `os_name` OsName, - /// Deprecated `os.name` from - OsNameDeprecated, /// `platform_machine` PlatformMachine, /// Deprecated `platform.machine` from - PlatformMachineDeprecated, /// `platform_python_implementation` PlatformPythonImplementation, - /// Deprecated `platform.python_implementation` from - PlatformPythonImplementationDeprecated, - /// Deprecated `python_implementation` from - PythonImplementationDeprecated, /// `platform_release` PlatformRelease, /// `platform_system` PlatformSystem, /// `platform_version` PlatformVersion, - /// Deprecated `platform.version` from - PlatformVersionDeprecated, /// `sys_platform` SysPlatform, - /// Deprecated `sys.platform` from - SysPlatformDeprecated, } impl From for LoweredMarkerValueString { @@ -84,22 +73,20 @@ impl From for LoweredMarkerValueString { match value { MarkerValueString::ImplementationName => Self::ImplementationName, MarkerValueString::OsName => Self::OsName, - MarkerValueString::OsNameDeprecated => Self::OsNameDeprecated, + MarkerValueString::OsNameDeprecated => Self::OsName, MarkerValueString::PlatformMachine => Self::PlatformMachine, - MarkerValueString::PlatformMachineDeprecated => Self::PlatformMachineDeprecated, + MarkerValueString::PlatformMachineDeprecated => Self::PlatformMachine, MarkerValueString::PlatformPythonImplementation => Self::PlatformPythonImplementation, MarkerValueString::PlatformPythonImplementationDeprecated => { - Self::PlatformPythonImplementationDeprecated - } - MarkerValueString::PythonImplementationDeprecated => { - Self::PythonImplementationDeprecated + Self::PlatformPythonImplementation } + MarkerValueString::PythonImplementationDeprecated => Self::PlatformPythonImplementation, MarkerValueString::PlatformRelease => Self::PlatformRelease, MarkerValueString::PlatformSystem => Self::PlatformSystem, MarkerValueString::PlatformVersion => Self::PlatformVersion, - MarkerValueString::PlatformVersionDeprecated => Self::PlatformVersionDeprecated, + MarkerValueString::PlatformVersionDeprecated => Self::PlatformVersion, MarkerValueString::SysPlatform => Self::SysPlatform, - MarkerValueString::SysPlatformDeprecated => Self::SysPlatformDeprecated, + MarkerValueString::SysPlatformDeprecated => Self::SysPlatform, } } } @@ -109,24 +96,14 @@ impl From for MarkerValueString { match value { LoweredMarkerValueString::ImplementationName => Self::ImplementationName, LoweredMarkerValueString::OsName => Self::OsName, - LoweredMarkerValueString::OsNameDeprecated => Self::OsNameDeprecated, LoweredMarkerValueString::PlatformMachine => Self::PlatformMachine, - LoweredMarkerValueString::PlatformMachineDeprecated => Self::PlatformMachineDeprecated, LoweredMarkerValueString::PlatformPythonImplementation => { Self::PlatformPythonImplementation } - LoweredMarkerValueString::PlatformPythonImplementationDeprecated => { - Self::PlatformPythonImplementationDeprecated - } - LoweredMarkerValueString::PythonImplementationDeprecated => { - Self::PythonImplementationDeprecated - } LoweredMarkerValueString::PlatformRelease => Self::PlatformRelease, LoweredMarkerValueString::PlatformSystem => Self::PlatformSystem, LoweredMarkerValueString::PlatformVersion => Self::PlatformVersion, - LoweredMarkerValueString::PlatformVersionDeprecated => Self::PlatformVersionDeprecated, LoweredMarkerValueString::SysPlatform => Self::SysPlatform, - LoweredMarkerValueString::SysPlatformDeprecated => Self::SysPlatformDeprecated, } } } @@ -136,19 +113,13 @@ impl Display for LoweredMarkerValueString { fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result { match self { Self::ImplementationName => f.write_str("implementation_name"), - Self::OsName | Self::OsNameDeprecated => f.write_str("os_name"), - Self::PlatformMachine | Self::PlatformMachineDeprecated => { - f.write_str("platform_machine") - } - Self::PlatformPythonImplementation - | Self::PlatformPythonImplementationDeprecated - | Self::PythonImplementationDeprecated => f.write_str("platform_python_implementation"), + Self::OsName => f.write_str("os_name"), + Self::PlatformMachine => f.write_str("platform_machine"), + Self::PlatformPythonImplementation => f.write_str("platform_python_implementation"), Self::PlatformRelease => f.write_str("platform_release"), Self::PlatformSystem => f.write_str("platform_system"), - Self::PlatformVersion | Self::PlatformVersionDeprecated => { - f.write_str("platform_version") - } - Self::SysPlatform | Self::SysPlatformDeprecated => f.write_str("sys_platform"), + Self::PlatformVersion => f.write_str("platform_version"), + Self::SysPlatform => f.write_str("sys_platform"), } } } diff --git a/crates/uv/tests/it/pip_compile.rs b/crates/uv/tests/it/pip_compile.rs index 618eb380f3e5..e73c2609826a 100644 --- a/crates/uv/tests/it/pip_compile.rs +++ b/crates/uv/tests/it/pip_compile.rs @@ -13626,3 +13626,36 @@ fn compile_derivation_chain() -> Result<()> { Ok(()) } + +/// Treat `sys_platform` and `sys.platform` as equivalent markers in the marker algebra. +#[test] +fn universal_disjoint_deprecated_markers() -> Result<()> { + let context = TestContext::new("3.12"); + let requirements_in = context.temp_dir.child("requirements.in"); + requirements_in.write_str(indoc::indoc! {r" + anyio ; sys_platform == 'win32' and sys.platform == 'win32' + typing-extensions ; platform.python_implementation == 'CPython' and python_implementation != 'CPython' + "})?; + + uv_snapshot!(context.filters(), context.pip_compile() + .arg("requirements.in") + .arg("--universal"), @r###" + success: true + exit_code: 0 + ----- stdout ----- + # This file was autogenerated by uv via the following command: + # uv pip compile --cache-dir [CACHE_DIR] requirements.in --universal + anyio==4.3.0 ; sys_platform == 'win32' + # via -r requirements.in + idna==3.6 ; sys_platform == 'win32' + # via anyio + sniffio==1.3.1 ; sys_platform == 'win32' + # via anyio + + ----- stderr ----- + Resolved 3 packages in [TIME] + "### + ); + + Ok(()) +}