Always attach linehaul data (#16705)

This commit is contained in:
Zsolt Dollenstein 2025-11-12 17:10:15 +00:00 committed by GitHub
parent 2c0d166260
commit e96354a6dd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 32 additions and 14 deletions

View file

@ -358,11 +358,9 @@ impl<'a> BaseClientBuilder<'a> {
let mut user_agent_string = format!("uv/{}", version()); let mut user_agent_string = format!("uv/{}", version());
// Add linehaul metadata. // Add linehaul metadata.
if let Some(markers) = self.markers { let linehaul = LineHaul::new(self.markers, self.platform);
let linehaul = LineHaul::new(markers, self.platform); if let Ok(output) = serde_json::to_string(&linehaul) {
if let Ok(output) = serde_json::to_string(&linehaul) { let _ = write!(user_agent_string, " {output}");
let _ = write!(user_agent_string, " {output}");
}
} }
// Check for the presence of an `SSL_CERT_FILE`. // Check for the presence of an `SSL_CERT_FILE`.

View file

@ -63,7 +63,7 @@ pub struct LineHaul {
impl LineHaul { impl LineHaul {
/// Initializes Linehaul information based on PEP 508 markers. /// Initializes Linehaul information based on PEP 508 markers.
#[instrument(name = "linehaul", skip_all)] #[instrument(name = "linehaul", skip_all)]
pub fn new(markers: &MarkerEnvironment, platform: Option<&Platform>) -> Self { pub fn new(markers: Option<&MarkerEnvironment>, platform: Option<&Platform>) -> Self {
// https://github.com/pypa/pip/blob/24.0/src/pip/_internal/network/session.py#L87 // https://github.com/pypa/pip/blob/24.0/src/pip/_internal/network/session.py#L87
let looks_like_ci = [ let looks_like_ci = [
EnvVars::BUILD_BUILDID, EnvVars::BUILD_BUILDID,
@ -124,17 +124,17 @@ impl LineHaul {
name: Some("uv".to_string()), name: Some("uv".to_string()),
version: Some(version().to_string()), version: Some(version().to_string()),
}), }),
python: Some(markers.python_full_version().version.to_string()), python: markers.map(|markers| markers.python_full_version().version.to_string()),
implementation: Option::from(Implementation { implementation: Option::from(Implementation {
name: Some(markers.platform_python_implementation().to_string()), name: markers.map(|markers| markers.platform_python_implementation().to_string()),
version: Some(markers.python_full_version().version.to_string()), version: markers.map(|markers| markers.python_full_version().version.to_string()),
}), }),
distro, distro,
system: Option::from(System { system: Option::from(System {
name: Some(markers.platform_system().to_string()), name: markers.map(|markers| markers.platform_system().to_string()),
release: Some(markers.platform_release().to_string()), release: markers.map(|markers| markers.platform_release().to_string()),
}), }),
cpu: Some(markers.platform_machine().to_string()), cpu: markers.map(|markers| markers.platform_machine().to_string()),
// Should probably always be None in uv. // Should probably always be None in uv.
openssl_version: None, openssl_version: None,
// Should probably always be None in uv. // Should probably always be None in uv.

View file

@ -70,8 +70,28 @@ async fn test_user_agent_has_version() -> Result<()> {
// Check User Agent // Check User Agent
let body = res.text().await?; let body = res.text().await?;
// Verify body matches regex let (uv_version, uv_linehaul) = body
assert_eq!(body, format!("uv/{}", version())); .split_once(' ')
.expect("Failed to split User-Agent header");
// Deserializing Linehaul
let linehaul: LineHaul = serde_json::from_str(uv_linehaul)?;
// Assert linehaul user agent
let filters = vec![(version(), "[VERSION]")];
with_settings!({
filters => filters
}, {
// Assert uv version
assert_snapshot!(uv_version, @"uv/[VERSION]");
// Assert linehaul json
assert_json_snapshot!(&linehaul.installer, @r#"
{
"name": "uv",
"version": "[VERSION]"
}
"#);
});
// Wait for the server task to complete, to be a good citizen. // Wait for the server task to complete, to be a good citizen.
server_task.await?; server_task.await?;