mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-02 21:02:37 +00:00
Use mac version from python for linehaul information (#2509)
See https://github.com/astral-sh/uv/pull/2493#pullrequestreview-1942899151. --------- Co-authored-by: Zanie Blue <contact@zanie.dev>
This commit is contained in:
parent
cfd18aa1a2
commit
32b9eeb532
7 changed files with 35 additions and 156 deletions
|
|
@ -28,7 +28,6 @@ fs-err = { workspace = true, features = ["tokio"] }
|
|||
futures = { workspace = true }
|
||||
html-escape = { workspace = true }
|
||||
http = { workspace = true }
|
||||
plist = { workspace = true }
|
||||
reqwest = { workspace = true }
|
||||
reqwest-middleware = { workspace = true }
|
||||
reqwest-retry = { workspace = true }
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ mod flat_index;
|
|||
mod html;
|
||||
mod httpcache;
|
||||
mod linehaul;
|
||||
mod mac_version;
|
||||
mod middleware;
|
||||
mod registry_client;
|
||||
mod remote_metadata;
|
||||
|
|
|
|||
|
|
@ -94,13 +94,17 @@ impl LineHaul {
|
|||
libc,
|
||||
})
|
||||
} else if cfg!(target_os = "macos") {
|
||||
let version = match platform.map(|platform| platform.os()) {
|
||||
Some(Os::Macos { major, minor }) => Some(format!("{major}.{minor}")),
|
||||
_ => None,
|
||||
};
|
||||
Some(Distro {
|
||||
// N/A
|
||||
id: None,
|
||||
// pip hardcodes distro name to macOS.
|
||||
name: Some("macOS".to_string()),
|
||||
// Same as python's platform.mac_ver[0].
|
||||
version: crate::mac_version::get_mac_os_version().ok(),
|
||||
// Same as python's platform.mac_ver()[0].
|
||||
version,
|
||||
// N/A
|
||||
libc: None,
|
||||
})
|
||||
|
|
@ -125,9 +129,12 @@ impl LineHaul {
|
|||
release: Some(markers.platform_release.to_string()),
|
||||
}),
|
||||
cpu: Some(markers.platform_machine.to_string()),
|
||||
openssl_version: None, // Should probably always be None in uv.
|
||||
setuptools_version: None, // Should probably always be None in uv.
|
||||
rustc_version: None, // Calling rustc --version is likely too slow.
|
||||
// Should probably always be None in uv.
|
||||
openssl_version: None,
|
||||
// Should probably always be None in uv.
|
||||
setuptools_version: None,
|
||||
// Calling rustc --version is likely too slow.
|
||||
rustc_version: None,
|
||||
ci: looks_like_ci,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,36 +0,0 @@
|
|||
use platform_tags::PlatformError;
|
||||
use serde::Deserialize;
|
||||
|
||||
/// Get the macOS version from the SystemVersion.plist file.
|
||||
pub(crate) fn get_mac_os_version() -> Result<String, PlatformError> {
|
||||
// This is actually what python does
|
||||
// https://github.com/python/cpython/blob/cb2b3c8d3566ae46b3b8d0718019e1c98484589e/Lib/platform.py#L409-L428
|
||||
#[derive(Deserialize)]
|
||||
#[serde(rename_all = "PascalCase")]
|
||||
struct SystemVersion {
|
||||
product_version: String,
|
||||
}
|
||||
let system_version: SystemVersion =
|
||||
plist::from_file("/System/Library/CoreServices/SystemVersion.plist")
|
||||
.map_err(|err| PlatformError::OsVersionDetectionError(err.to_string()))?;
|
||||
|
||||
let invalid_mac_os_version = || {
|
||||
PlatformError::OsVersionDetectionError(format!(
|
||||
"Invalid macOS version {}",
|
||||
system_version.product_version
|
||||
))
|
||||
};
|
||||
match system_version
|
||||
.product_version
|
||||
.split('.')
|
||||
.collect::<Vec<&str>>()
|
||||
.as_slice()
|
||||
{
|
||||
[major, minor] | [major, minor, _] => {
|
||||
let _major = major.parse::<u16>().map_err(|_| invalid_mac_os_version())?;
|
||||
let _minor = minor.parse::<u16>().map_err(|_| invalid_mac_os_version())?;
|
||||
Ok(system_version.product_version)
|
||||
}
|
||||
_ => Err(invalid_mac_os_version()),
|
||||
}
|
||||
}
|
||||
|
|
@ -114,21 +114,29 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
|
|||
},
|
||||
sys_platform: "linux".to_string(),
|
||||
};
|
||||
// Linux only
|
||||
let platform = Platform::new(
|
||||
|
||||
// Initialize uv-client
|
||||
let cache = Cache::temp()?;
|
||||
let mut builder = RegistryClientBuilder::new(cache).markers(&markers);
|
||||
|
||||
let linux = Platform::new(
|
||||
Os::Manylinux {
|
||||
major: 2,
|
||||
minor: 38,
|
||||
},
|
||||
Arch::X86_64,
|
||||
);
|
||||
|
||||
// Initialize uv-client
|
||||
let cache = Cache::temp()?;
|
||||
let mut builder = RegistryClientBuilder::new(cache).markers(&markers);
|
||||
|
||||
let macos = Platform::new(
|
||||
Os::Macos {
|
||||
major: 14,
|
||||
minor: 4,
|
||||
},
|
||||
Arch::Aarch64,
|
||||
);
|
||||
if cfg!(target_os = "linux") {
|
||||
builder = builder.platform(&platform);
|
||||
builder = builder.platform(&linux);
|
||||
} else if cfg!(target_os = "macos") {
|
||||
builder = builder.platform(&macos);
|
||||
}
|
||||
let client = builder.build();
|
||||
|
||||
|
|
@ -186,28 +194,22 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
|
|||
assert_eq!(linehaul.setuptools_version, None);
|
||||
assert_eq!(linehaul.rustc_version, None);
|
||||
|
||||
#[cfg(windows)]
|
||||
assert_eq!(linehaul.distro, None);
|
||||
|
||||
// Using os_info as to confirm our values are as expected in both Linux and OSX.
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
if cfg!(windows) {
|
||||
assert_eq!(linehaul.distro, None);
|
||||
} else if cfg!(target_os = "linux") {
|
||||
// Using `os_info` to confirm our values are as expected in Linux
|
||||
let info = os_info::get();
|
||||
let distro_info = linehaul.distro.unwrap();
|
||||
assert_eq!(distro_info.id.unwrap(), info.codename().unwrap());
|
||||
assert_eq!(distro_info.name.unwrap(), info.os_type().to_string());
|
||||
assert_eq!(distro_info.version.unwrap(), info.version().to_string());
|
||||
assert!(distro_info.libc.is_some());
|
||||
}
|
||||
|
||||
// Using os_info as sys-info yields Darwin version, and not mac release version.
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let info = os_info::get();
|
||||
} else if cfg!(target_os = "macos") {
|
||||
// We mock the macOS version
|
||||
let distro_info = linehaul.distro.unwrap();
|
||||
assert_eq!(distro_info.id, None);
|
||||
assert_eq!(distro_info.name.unwrap(), "macOS");
|
||||
assert_eq!(distro_info.version.unwrap(), info.version().to_string());
|
||||
assert_eq!(distro_info.version, Some("14.4".to_string()));
|
||||
assert_eq!(distro_info.libc, None);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue