From dea17009455249b7c76a8575d73dd76c7796a0fc Mon Sep 17 00:00:00 2001 From: Charlie Marsh Date: Wed, 17 Sep 2025 10:30:43 -0400 Subject: [PATCH] Avoid ANSI codes in debug! messages (#15843) ## Summary I spent time trying to figure out how to support this but came up empty. It _seems_ like maybe the `DefaultFields` implementation in `tracing-subscriber` uses debug formatting for fields...? So if you have a string with ANSI codes, they end up printing as unformatted values? I even reverted all our custom formatting in `logging.rs` and saw the same thing. Closes https://github.com/astral-sh/uv/issues/15840. --- crates/uv-auth/src/middleware.rs | 2 +- crates/uv-distribution/src/source/mod.rs | 2 +- crates/uv-installer/src/satisfies.rs | 37 ++++++++++++------------ crates/uv-python/src/downloads.rs | 4 +-- crates/uv/src/commands/python/install.rs | 19 +++++------- 5 files changed, 29 insertions(+), 35 deletions(-) diff --git a/crates/uv-auth/src/middleware.rs b/crates/uv-auth/src/middleware.rs index 90a902af9..febe76d60 100644 --- a/crates/uv-auth/src/middleware.rs +++ b/crates/uv-auth/src/middleware.rs @@ -2235,7 +2235,7 @@ mod tests { assert!(matches!( client.get(server.uri()).send().await, Err(reqwest_middleware::Error::Middleware(_)) - ),); + )); Ok(()) } diff --git a/crates/uv-distribution/src/source/mod.rs b/crates/uv-distribution/src/source/mod.rs index 1bedb7cba..1a22ada94 100644 --- a/crates/uv-distribution/src/source/mod.rs +++ b/crates/uv-distribution/src/source/mod.rs @@ -1469,7 +1469,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> { } Ok(None) => {} Err(err) => { - debug!("Failed to deserialize cached revision for: {source} ({err})",); + debug!("Failed to deserialize cached revision for: {source} ({err})"); } } } diff --git a/crates/uv-installer/src/satisfies.rs b/crates/uv-installer/src/satisfies.rs index 5bcf82483..9808bbdc4 100644 --- a/crates/uv-installer/src/satisfies.rs +++ b/crates/uv-installer/src/satisfies.rs @@ -1,7 +1,6 @@ use std::borrow::Cow; use std::fmt::Debug; -use owo_colors::OwoColorize; use same_file::is_same_file; use tracing::{debug, trace}; use url::Url; @@ -399,18 +398,18 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O if let Some(current) = current_tag { let message = if let Some(pretty) = current.pretty() { - format!("{} (`{}`)", pretty.cyan(), current.cyan()) + format!("{pretty} (`{current}`)") } else { - format!("`{}`", current.cyan()) + format!("`{current}`") }; Some(format!( "The distribution is compatible with {}, but you're using {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", "), @@ -421,9 +420,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O "The distribution requires {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", ") @@ -436,17 +435,17 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O if let Some(current) = current_tag { let message = if let Some(pretty) = current.pretty() { - format!("{} (`{}`)", pretty.cyan(), current.cyan()) + format!("{pretty} (`{current}`)") } else { - format!("`{}`", current.cyan()) + format!("`{current}`") }; Some(format!( "The distribution is compatible with {}, but you're using {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", "), @@ -457,9 +456,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O "The distribution requires {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", ") @@ -472,17 +471,17 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O if let Some(current) = current_tag { let message = if let Some(pretty) = current.pretty() { - format!("{} (`{}`)", pretty.cyan(), current.cyan()) + format!("{pretty} (`{current}`)") } else { - format!("`{}`", current.cyan()) + format!("`{current}`") }; Some(format!( "The distribution is compatible with {}, but you're on {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", "), @@ -493,9 +492,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O "The distribution requires {}", wheel_tags .map(|tag| if let Some(pretty) = tag.pretty() { - format!("{} (`{}`)", pretty.cyan(), tag.cyan()) + format!("{pretty} (`{tag}`)") } else { - format!("`{}`", tag.cyan()) + format!("`{tag}`") }) .collect::>() .join(", ") diff --git a/crates/uv-python/src/downloads.rs b/crates/uv-python/src/downloads.rs index b0077f161..b637a3a68 100644 --- a/crates/uv-python/src/downloads.rs +++ b/crates/uv-python/src/downloads.rs @@ -1728,8 +1728,8 @@ mod tests { request.version, Some(VersionRequest::from_str("3.13.0rc1").unwrap()) ); - assert_eq!(request.os, None,); - assert_eq!(request.arch, None,); + assert_eq!(request.os, None); + assert_eq!(request.arch, None); assert_eq!(request.libc, None); } diff --git a/crates/uv/src/commands/python/install.rs b/crates/uv/src/commands/python/install.rs index 05beb7e3c..22640239e 100644 --- a/crates/uv/src/commands/python/install.rs +++ b/crates/uv/src/commands/python/install.rs @@ -312,7 +312,7 @@ pub(crate) async fn install( .peekable(); if matching_installations.peek().is_none() { - debug!("No installation found for request `{}`", request.cyan()); + debug!("No installation found for request `{}`", request); unsatisfied.push(Cow::Borrowed(request)); } @@ -325,7 +325,7 @@ pub(crate) async fn install( python_downloads_json_url.as_deref(), ) { Ok(request) => { - debug!("Will reinstall `{}`", installation.key().green()); + debug!("Will reinstall `{}`", installation.key()); unsatisfied.push(Cow::Owned(request)); } Err(err) => { @@ -344,8 +344,8 @@ pub(crate) async fn install( // If we have real requests, just ignore the existing installation debug!( "Ignoring match `{}` for request `{}` due to `--reinstall` flag", - installation.key().green(), - request.cyan() + installation.key(), + request ); unsatisfied.push(Cow::Borrowed(request)); break; @@ -366,14 +366,10 @@ pub(crate) async fn install( request.matches_installation(installation) } }) { - debug!( - "Found `{}` for request `{}`", - installation.key().green(), - request.cyan(), - ); + debug!("Found `{}` for request `{}`", installation.key(), request); Either::Left(installation) } else { - debug!("No installation found for request `{}`", request.cyan()); + debug!("No installation found for request `{}`", request); Either::Right(Cow::Borrowed(request)) } }) @@ -394,8 +390,7 @@ pub(crate) async fn install( .inspect(|request| { debug!( "Found download `{}` for request `{}`", - request.download, - request.cyan(), + request.download, request, ); }) .map(|request| request.download)