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.
This commit is contained in:
Charlie Marsh 2025-09-17 10:30:43 -04:00 committed by GitHub
parent 48f507680c
commit dea1700945
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 35 deletions

View File

@ -2235,7 +2235,7 @@ mod tests {
assert!(matches!( assert!(matches!(
client.get(server.uri()).send().await, client.get(server.uri()).send().await,
Err(reqwest_middleware::Error::Middleware(_)) Err(reqwest_middleware::Error::Middleware(_))
),); ));
Ok(()) Ok(())
} }

View File

@ -1469,7 +1469,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
} }
Ok(None) => {} Ok(None) => {}
Err(err) => { Err(err) => {
debug!("Failed to deserialize cached revision for: {source} ({err})",); debug!("Failed to deserialize cached revision for: {source} ({err})");
} }
} }
} }

View File

@ -1,7 +1,6 @@
use std::borrow::Cow; use std::borrow::Cow;
use std::fmt::Debug; use std::fmt::Debug;
use owo_colors::OwoColorize;
use same_file::is_same_file; use same_file::is_same_file;
use tracing::{debug, trace}; use tracing::{debug, trace};
use url::Url; use url::Url;
@ -399,18 +398,18 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
if let Some(current) = current_tag { if let Some(current) = current_tag {
let message = if let Some(pretty) = current.pretty() { let message = if let Some(pretty) = current.pretty() {
format!("{} (`{}`)", pretty.cyan(), current.cyan()) format!("{pretty} (`{current}`)")
} else { } else {
format!("`{}`", current.cyan()) format!("`{current}`")
}; };
Some(format!( Some(format!(
"The distribution is compatible with {}, but you're using {}", "The distribution is compatible with {}, but you're using {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
@ -421,9 +420,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
"The distribution requires {}", "The distribution requires {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
@ -436,17 +435,17 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
if let Some(current) = current_tag { if let Some(current) = current_tag {
let message = if let Some(pretty) = current.pretty() { let message = if let Some(pretty) = current.pretty() {
format!("{} (`{}`)", pretty.cyan(), current.cyan()) format!("{pretty} (`{current}`)")
} else { } else {
format!("`{}`", current.cyan()) format!("`{current}`")
}; };
Some(format!( Some(format!(
"The distribution is compatible with {}, but you're using {}", "The distribution is compatible with {}, but you're using {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
@ -457,9 +456,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
"The distribution requires {}", "The distribution requires {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")
@ -472,17 +471,17 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
if let Some(current) = current_tag { if let Some(current) = current_tag {
let message = if let Some(pretty) = current.pretty() { let message = if let Some(pretty) = current.pretty() {
format!("{} (`{}`)", pretty.cyan(), current.cyan()) format!("{pretty} (`{current}`)")
} else { } else {
format!("`{}`", current.cyan()) format!("`{current}`")
}; };
Some(format!( Some(format!(
"The distribution is compatible with {}, but you're on {}", "The distribution is compatible with {}, but you're on {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", "), .join(", "),
@ -493,9 +492,9 @@ fn generate_dist_compatibility_hint(wheel_tags: &ExpandedTags, tags: &Tags) -> O
"The distribution requires {}", "The distribution requires {}",
wheel_tags wheel_tags
.map(|tag| if let Some(pretty) = tag.pretty() { .map(|tag| if let Some(pretty) = tag.pretty() {
format!("{} (`{}`)", pretty.cyan(), tag.cyan()) format!("{pretty} (`{tag}`)")
} else { } else {
format!("`{}`", tag.cyan()) format!("`{tag}`")
}) })
.collect::<Vec<_>>() .collect::<Vec<_>>()
.join(", ") .join(", ")

View File

@ -1728,8 +1728,8 @@ mod tests {
request.version, request.version,
Some(VersionRequest::from_str("3.13.0rc1").unwrap()) Some(VersionRequest::from_str("3.13.0rc1").unwrap())
); );
assert_eq!(request.os, None,); assert_eq!(request.os, None);
assert_eq!(request.arch, None,); assert_eq!(request.arch, None);
assert_eq!(request.libc, None); assert_eq!(request.libc, None);
} }

View File

@ -312,7 +312,7 @@ pub(crate) async fn install(
.peekable(); .peekable();
if matching_installations.peek().is_none() { 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)); unsatisfied.push(Cow::Borrowed(request));
} }
@ -325,7 +325,7 @@ pub(crate) async fn install(
python_downloads_json_url.as_deref(), python_downloads_json_url.as_deref(),
) { ) {
Ok(request) => { Ok(request) => {
debug!("Will reinstall `{}`", installation.key().green()); debug!("Will reinstall `{}`", installation.key());
unsatisfied.push(Cow::Owned(request)); unsatisfied.push(Cow::Owned(request));
} }
Err(err) => { Err(err) => {
@ -344,8 +344,8 @@ pub(crate) async fn install(
// If we have real requests, just ignore the existing installation // If we have real requests, just ignore the existing installation
debug!( debug!(
"Ignoring match `{}` for request `{}` due to `--reinstall` flag", "Ignoring match `{}` for request `{}` due to `--reinstall` flag",
installation.key().green(), installation.key(),
request.cyan() request
); );
unsatisfied.push(Cow::Borrowed(request)); unsatisfied.push(Cow::Borrowed(request));
break; break;
@ -366,14 +366,10 @@ pub(crate) async fn install(
request.matches_installation(installation) request.matches_installation(installation)
} }
}) { }) {
debug!( debug!("Found `{}` for request `{}`", installation.key(), request);
"Found `{}` for request `{}`",
installation.key().green(),
request.cyan(),
);
Either::Left(installation) Either::Left(installation)
} else { } else {
debug!("No installation found for request `{}`", request.cyan()); debug!("No installation found for request `{}`", request);
Either::Right(Cow::Borrowed(request)) Either::Right(Cow::Borrowed(request))
} }
}) })
@ -394,8 +390,7 @@ pub(crate) async fn install(
.inspect(|request| { .inspect(|request| {
debug!( debug!(
"Found download `{}` for request `{}`", "Found download `{}` for request `{}`",
request.download, request.download, request,
request.cyan(),
); );
}) })
.map(|request| request.download) .map(|request| request.download)