mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-01 04:17: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
91
Cargo.lock
generated
91
Cargo.lock
generated
|
|
@ -940,15 +940,6 @@ version = "0.1.3"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "63dfa964fe2a66f3fde91fc70b267fe193d822c7e603e2a675a49a7f46ad3f49"
|
||||
|
||||
[[package]]
|
||||
name = "deranged"
|
||||
version = "0.3.11"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b42b6fa04a440b495c8b04d0e71b707c585f83cb9cb28cf8cd0d976c315e31b4"
|
||||
dependencies = [
|
||||
"powerfmt",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "derivative"
|
||||
version = "2.2.0"
|
||||
|
|
@ -2046,15 +2037,6 @@ dependencies = [
|
|||
"vcpkg",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "line-wrap"
|
||||
version = "0.1.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9"
|
||||
dependencies = [
|
||||
"safemem",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "linked-hash-map"
|
||||
version = "0.5.6"
|
||||
|
|
@ -2312,12 +2294,6 @@ dependencies = [
|
|||
"windows-sys 0.48.0",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "num-conv"
|
||||
version = "0.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "51d515d32fb182ee37cda2ccdcb92950d6a3c2893aa280e540671c2cd0f3b1d9"
|
||||
|
||||
[[package]]
|
||||
name = "num-traits"
|
||||
version = "0.2.18"
|
||||
|
|
@ -2619,20 +2595,6 @@ dependencies = [
|
|||
"thiserror",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "plist"
|
||||
version = "1.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e5699cc8a63d1aa2b1ee8e12b9ad70ac790d65788cd36101fa37f87ea46c4cef"
|
||||
dependencies = [
|
||||
"base64 0.21.7",
|
||||
"indexmap 2.2.5",
|
||||
"line-wrap",
|
||||
"quick-xml",
|
||||
"serde",
|
||||
"time",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "png"
|
||||
version = "0.17.13"
|
||||
|
|
@ -2661,12 +2623,6 @@ version = "1.6.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7170ef9988bc169ba16dd36a7fa041e5c4cbeb6a35b76d4c03daded371eae7c0"
|
||||
|
||||
[[package]]
|
||||
name = "powerfmt"
|
||||
version = "0.2.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "439ee305def115ba05938db6eb1644ff94165c5ab5e9420d1c1bcedbba909391"
|
||||
|
||||
[[package]]
|
||||
name = "ppv-lite86"
|
||||
version = "0.2.17"
|
||||
|
|
@ -2859,15 +2815,6 @@ dependencies = [
|
|||
"toml",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quick-xml"
|
||||
version = "0.31.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1004a344b30a54e2ee58d66a71b32d2db2feb0a31f9a2d302bf0536f15de2a33"
|
||||
dependencies = [
|
||||
"memchr",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.35"
|
||||
|
|
@ -3390,12 +3337,6 @@ version = "1.0.17"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
|
||||
|
||||
[[package]]
|
||||
name = "safemem"
|
||||
version = "0.3.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef703b7cb59335eae2eb93ceb664c0eb7ea6bf567079d843e09420219668e072"
|
||||
|
||||
[[package]]
|
||||
name = "same-file"
|
||||
version = "1.0.6"
|
||||
|
|
@ -3928,37 +3869,6 @@ dependencies = [
|
|||
"tikv-jemalloc-sys",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time"
|
||||
version = "0.3.34"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c8248b6521bb14bc45b4067159b9b6ad792e2d6d754d6c41fb50e29fefe38749"
|
||||
dependencies = [
|
||||
"deranged",
|
||||
"itoa",
|
||||
"num-conv",
|
||||
"powerfmt",
|
||||
"serde",
|
||||
"time-core",
|
||||
"time-macros",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "time-core"
|
||||
version = "0.1.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef927ca75afb808a4d64dd374f00a2adf8d0fcff8e7b184af886c3c87ec4a3f3"
|
||||
|
||||
[[package]]
|
||||
name = "time-macros"
|
||||
version = "0.2.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "7ba3a3ef41e6672a2f0f001392bb5dcd3ff0a9992d618ca761a11c3121547774"
|
||||
dependencies = [
|
||||
"num-conv",
|
||||
"time-core",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "tiny-skia"
|
||||
version = "0.8.4"
|
||||
|
|
@ -4587,7 +4497,6 @@ dependencies = [
|
|||
"pep440_rs",
|
||||
"pep508_rs",
|
||||
"platform-tags",
|
||||
"plist",
|
||||
"pypi-types",
|
||||
"reqwest",
|
||||
"reqwest-middleware",
|
||||
|
|
|
|||
|
|
@ -68,7 +68,6 @@ owo-colors = { version = "4.0.0" }
|
|||
pathdiff = { version = "0.2.1" }
|
||||
petgraph = { version = "0.6.4" }
|
||||
platform-info = { version = "2.0.2" }
|
||||
plist = { version = "1.6.0" }
|
||||
pubgrub = { git = "https://github.com/astral-sh/pubgrub", rev = "addbaf184891d66a2dfd93d241a66d13bfe5de86" }
|
||||
pyo3 = { version = "0.20.3" }
|
||||
pyo3-log = { version = "0.9.0" }
|
||||
|
|
|
|||
|
|
@ -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