mirror of
https://github.com/astral-sh/uv.git
synced 2025-11-17 18:57:30 +00:00
Always attach linehaul data (#16705)
This commit is contained in:
parent
2c0d166260
commit
e96354a6dd
3 changed files with 32 additions and 14 deletions
|
|
@ -358,11 +358,9 @@ impl<'a> BaseClientBuilder<'a> {
|
|||
let mut user_agent_string = format!("uv/{}", version());
|
||||
|
||||
// Add linehaul metadata.
|
||||
if let Some(markers) = self.markers {
|
||||
let linehaul = LineHaul::new(markers, self.platform);
|
||||
if let Ok(output) = serde_json::to_string(&linehaul) {
|
||||
let _ = write!(user_agent_string, " {output}");
|
||||
}
|
||||
let linehaul = LineHaul::new(self.markers, self.platform);
|
||||
if let Ok(output) = serde_json::to_string(&linehaul) {
|
||||
let _ = write!(user_agent_string, " {output}");
|
||||
}
|
||||
|
||||
// Check for the presence of an `SSL_CERT_FILE`.
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ pub struct LineHaul {
|
|||
impl LineHaul {
|
||||
/// Initializes Linehaul information based on PEP 508 markers.
|
||||
#[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
|
||||
let looks_like_ci = [
|
||||
EnvVars::BUILD_BUILDID,
|
||||
|
|
@ -124,17 +124,17 @@ impl LineHaul {
|
|||
name: Some("uv".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 {
|
||||
name: Some(markers.platform_python_implementation().to_string()),
|
||||
version: Some(markers.python_full_version().version.to_string()),
|
||||
name: markers.map(|markers| markers.platform_python_implementation().to_string()),
|
||||
version: markers.map(|markers| markers.python_full_version().version.to_string()),
|
||||
}),
|
||||
distro,
|
||||
system: Option::from(System {
|
||||
name: Some(markers.platform_system().to_string()),
|
||||
release: Some(markers.platform_release().to_string()),
|
||||
name: markers.map(|markers| markers.platform_system().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.
|
||||
openssl_version: None,
|
||||
// Should probably always be None in uv.
|
||||
|
|
|
|||
|
|
@ -70,8 +70,28 @@ async fn test_user_agent_has_version() -> Result<()> {
|
|||
// Check User Agent
|
||||
let body = res.text().await?;
|
||||
|
||||
// Verify body matches regex
|
||||
assert_eq!(body, format!("uv/{}", version()));
|
||||
let (uv_version, uv_linehaul) = body
|
||||
.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.
|
||||
server_task.await?;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue