Skip to content

Commit

Permalink
Treat deprecated aliases as equivalent in marker algebra
Browse files Browse the repository at this point in the history
  • Loading branch information
charliermarsh committed Nov 26, 2024
1 parent 1068630 commit cb675b7
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 52 deletions.
17 changes: 5 additions & 12 deletions crates/uv-pep508/src/marker/environment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
}
Expand Down
51 changes: 11 additions & 40 deletions crates/uv-pep508/src/marker/lowering.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,53 +53,40 @@ pub enum LoweredMarkerValueString {
ImplementationName,
/// `os_name`
OsName,
/// Deprecated `os.name` from <https://peps.python.org/pep-0345/#environment-markers>
OsNameDeprecated,
/// `platform_machine`
PlatformMachine,
/// Deprecated `platform.machine` from <https://peps.python.org/pep-0345/#environment-markers>
PlatformMachineDeprecated,
/// `platform_python_implementation`
PlatformPythonImplementation,
/// Deprecated `platform.python_implementation` from <https://peps.python.org/pep-0345/#environment-markers>
PlatformPythonImplementationDeprecated,
/// Deprecated `python_implementation` from <https://github.com/pypa/packaging/issues/72>
PythonImplementationDeprecated,
/// `platform_release`
PlatformRelease,
/// `platform_system`
PlatformSystem,
/// `platform_version`
PlatformVersion,
/// Deprecated `platform.version` from <https://peps.python.org/pep-0345/#environment-markers>
PlatformVersionDeprecated,
/// `sys_platform`
SysPlatform,
/// Deprecated `sys.platform` from <https://peps.python.org/pep-0345/#environment-markers>
SysPlatformDeprecated,
}

impl From<MarkerValueString> for LoweredMarkerValueString {
fn from(value: MarkerValueString) -> Self {
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,
}
}
}
Expand All @@ -109,24 +96,14 @@ impl From<LoweredMarkerValueString> 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,
}
}
}
Expand All @@ -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"),
}
}
}
Expand Down
33 changes: 33 additions & 0 deletions crates/uv/tests/it/pip_compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}

0 comments on commit cb675b7

Please sign in to comment.