Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 39 additions & 6 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ sha2 = { version = "0.10.8" }
smallvec = { version = "1.13.2" }
spdx = { version = "0.12.0" }
syn = { version = "2.0.77" }
sys-info = { version = "0.9.1" }
sysinfo = { version = "0.37.2" }
tar = { version = "0.4.43" }
target-lexicon = { version = "0.13.0" }
tempfile = { version = "3.14.0" }
Expand Down
2 changes: 1 addition & 1 deletion crates/uv-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ rmp-serde = { workspace = true }
rustc-hash = { workspace = true }
serde = { workspace = true }
serde_json = { workspace = true }
sys-info = { workspace = true }
sysinfo = { workspace = true }
thiserror = { workspace = true }
tokio = { workspace = true }
tokio-util = { workspace = true }
Expand Down
32 changes: 28 additions & 4 deletions crates/uv-client/src/linehaul.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use std::env;
use std::io::Read;

use serde::{Deserialize, Serialize};
use tracing::instrument;
Expand Down Expand Up @@ -89,13 +90,13 @@ impl LineHaul {
// Build Distro as Linehaul expects.
let distro: Option<Distro> = if cfg!(target_os = "linux") {
// Gather distribution info from /etc/os-release.
sys_info::linux_os_release().ok().map(|info| Distro {
Some(Distro {
// e.g., Jammy, Focal, etc.
id: info.version_codename,
id: Self::get_version_codename().ok().flatten(),
// e.g., Ubuntu, Fedora, etc.
name: info.name,
name: sysinfo::System::name(),
// e.g., 22.04, etc.
version: info.version_id,
version: sysinfo::System::os_version(),
// e.g., glibc 2.38, musl 1.2
libc,
})
Expand Down Expand Up @@ -144,4 +145,27 @@ impl LineHaul {
ci: looks_like_ci,
}
}

// https://docs.rs/sys-info/latest/src/sys_info/lib.rs.html#473-515
fn get_version_codename() -> Result<Option<String>, std::io::Error> {
if !cfg!(target_os = "linux") {
return Ok(None);
}

let mut s = String::new();
fs_err::File::open("/etc/os-release")?.read_to_string(&mut s)?;

for line in s.lines() {
let line = line.trim();
if line.starts_with("VERSION_CODENAME=") {
let value = line
.strip_prefix("VERSION_CODENAME=")
.unwrap()
.trim_matches('"');
return Ok(Some(value.to_string()));
}
}

Ok(None)
}
}
38 changes: 32 additions & 6 deletions crates/uv-client/tests/it/user_agent_version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ use std::str::FromStr;

use anyhow::Result;
use insta::{assert_json_snapshot, assert_snapshot, with_settings};
use std::io::Read;
use std::str::FromStr;
use tokio::net::TcpListener;
use url::Url;

use uv_cache::Cache;
Expand All @@ -12,6 +15,28 @@ use uv_platform_tags::{Arch, Os, Platform};
use uv_redacted::DisplaySafeUrl;
use uv_version::version;

// https://docs.rs/sys-info/latest/src/sys_info/lib.rs.html#473-515
fn get_version_codename() -> Result<Option<String>, std::io::Error> {
if !cfg!(target_os = "linux") {
return Ok(None);
}

let mut s = String::new();
fs_err::File::open("/etc/os-release")?.read_to_string(&mut s)?;

for line in s.lines() {
let line = line.trim();
if line.starts_with("VERSION_CODENAME=") {
let value = line
.strip_prefix("VERSION_CODENAME=")
.unwrap()
.trim_matches('"');
return Ok(Some(value.to_string()));
}
}

Ok(None)
}
use crate::http_util::start_http_user_agent_server;

#[tokio::test]
Expand Down Expand Up @@ -201,12 +226,13 @@ async fn test_user_agent_has_linehaul() -> Result<()> {
let distro_info = linehaul
.distro
.expect("got no distro, but expected one in linehaul");
// Gather distribution info from /etc/os-release.
let release_info = sys_info::linux_os_release()
.expect("got no os release info, but expected one in linux");
assert_eq!(distro_info.id, release_info.version_codename);
assert_eq!(distro_info.name, release_info.name);
assert_eq!(distro_info.version, release_info.version_id);
// Gather distribution info using sysinfo and custom parsing
let codename = get_version_codename().ok().flatten();
let name = sysinfo::System::name();
let version = sysinfo::System::os_version();
assert_eq!(distro_info.id, codename);
assert_eq!(distro_info.name, name);
assert_eq!(distro_info.version, version);
} else if cfg!(target_os = "macos") {
// We mock the macOS distro
assert_json_snapshot!(&linehaul.distro, @r###"
Expand Down
3 changes: 2 additions & 1 deletion crates/uv-python/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ same-file = { workspace = true }
schemars = { workspace = true, optional = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
sys-info = { workspace = true }
sysinfo = { workspace = true }
target-lexicon = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }
Expand All @@ -66,6 +66,7 @@ tokio-util = { workspace = true, features = ["compat"] }
tracing = { workspace = true }
url = { workspace = true }
which = { workspace = true }
heck = "0.5.0"

[target.'cfg(target_os = "windows")'.dependencies]
windows-registry = { workspace = true }
Expand Down
7 changes: 5 additions & 2 deletions crates/uv-python/src/interpreter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ use std::{env, io};

use configparser::ini::Ini;
use fs_err as fs;
use heck::ToTitleCase;
use owo_colors::OwoColorize;
use same_file::is_same_file;
use serde::{Deserialize, Serialize};
use sysinfo::System;
use thiserror::Error;
use tracing::{debug, trace, warn};

Expand Down Expand Up @@ -1095,10 +1097,11 @@ impl InterpreterInfo {
CacheBucket::Interpreter,
// Shard interpreter metadata by host architecture, operating system, and version, to
// invalidate the cache (e.g.) on OS upgrades.
// std::env::consts::OS (e.g., "linux", "macos", "windows")
cache_digest(&(
ARCH,
sys_info::os_type().unwrap_or_default(),
sys_info::os_release().unwrap_or_default(),
std::env::consts::OS.to_title_case(),
System::kernel_version().unwrap_or_default(),
)),
// We use the absolute path for the cache entry to avoid cache collisions for relative
// paths. But we don't want to query the executable with symbolic links resolved because
Expand Down
Loading