From 05da6f7a648a75e984442bc4b43202eb5058229b Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Wed, 17 Jun 2026 14:11:08 +0100 Subject: [PATCH] Add hidden --show-version to uv check Mirror uv format's hidden version-reporting flag for uv check. When requested, uv now reports the selected ty version for both TY overrides and downloaded ty binaries without running an extra override version probe only for debug logging. --- crates/uv-cli/src/lib.rs | 4 ++++ crates/uv/src/commands/project/check.rs | 2 ++ crates/uv/src/commands/project/check/ty.rs | 11 +++++++++-- crates/uv/src/lib.rs | 1 + crates/uv/src/settings.rs | 3 +++ crates/uv/tests/project/check.rs | 19 +++++++++---------- 6 files changed, 28 insertions(+), 12 deletions(-) diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 8bc087b038747..9a63f7a929b2d 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -5388,6 +5388,10 @@ pub struct CheckArgs { #[arg(long, value_hint = ValueHint::Other)] pub ty_version: Option, + /// Display the version of ty that will be used for type checking. + #[arg(long, hide = true)] + pub show_version: bool, + /// Avoid discovering a project or workspace. /// /// Instead of running checks in the context of the current project, run them in the context of diff --git a/crates/uv/src/commands/project/check.rs b/crates/uv/src/commands/project/check.rs index 974ad3c193614..16fb52160cfd0 100644 --- a/crates/uv/src/commands/project/check.rs +++ b/crates/uv/src/commands/project/check.rs @@ -49,6 +49,7 @@ pub(crate) async fn check( install_mirrors: PythonInstallMirrors, settings: ResolverInstallerSettings, ty_version: Option, + show_version: bool, client_builder: BaseClientBuilder<'_>, python_preference: PythonPreference, python_downloads: PythonDownloads, @@ -387,6 +388,7 @@ pub(crate) async fn check( venv_path.as_deref(), workspace_metadata, exclude_newer, + show_version, &client_builder, cache, printer, diff --git a/crates/uv/src/commands/project/check/ty.rs b/crates/uv/src/commands/project/check/ty.rs index c087682c8834c..0bed8170f1b08 100644 --- a/crates/uv/src/commands/project/check/ty.rs +++ b/crates/uv/src/commands/project/check/ty.rs @@ -1,3 +1,4 @@ +use std::fmt::Write; use std::path::{Path, PathBuf}; use std::process::Stdio; use std::str::FromStr; @@ -42,12 +43,13 @@ pub(super) async fn run( venv_path: Option<&Path>, workspace_metadata: Option, exclude_newer: Option, + show_version: bool, client_builder: &BaseClientBuilder<'_>, cache: &Cache, printer: Printer, ) -> Result { let ty_path = if let Some(ty_path) = ty_path { - if tracing::enabled!(tracing::Level::DEBUG) { + if show_version { let output = Command::new(&ty_path) .arg("--version") .output() @@ -56,7 +58,8 @@ pub(super) async fn run( if !output.status.success() { anyhow::bail!("Failed to query ty version"); } - debug!("Using `{}`", String::from_utf8_lossy(&output.stdout).trim()); + let version = String::from_utf8_lossy(&output.stdout); + writeln!(printer.stderr(), "Using {}", version.trim())?; } ty_path } else { @@ -123,6 +126,10 @@ pub(super) async fn run( } }; + if show_version { + writeln!(printer.stderr(), "Using ty {}", resolved.version)?; + } + bin_install( Binary::Ty, &resolved, diff --git a/crates/uv/src/lib.rs b/crates/uv/src/lib.rs index 2fd4a4ac89544..fbcdf01b5e803 100644 --- a/crates/uv/src/lib.rs +++ b/crates/uv/src/lib.rs @@ -2800,6 +2800,7 @@ async fn run_project( args.install_mirrors, args.settings, args.ty_version, + args.show_version, client_builder.subcommand(vec!["check".to_owned()]), globals.python_preference, globals.python_downloads, diff --git a/crates/uv/src/settings.rs b/crates/uv/src/settings.rs index 2323d7d72b285..fd823aa84183e 100644 --- a/crates/uv/src/settings.rs +++ b/crates/uv/src/settings.rs @@ -2986,6 +2986,7 @@ pub(crate) struct CheckSettings { pub(crate) refresh: Refresh, pub(crate) settings: ResolverInstallerSettings, pub(crate) ty_version: Option, + pub(crate) show_version: bool, pub(crate) no_project: bool, pub(crate) malware_settings: MalwareCheckSettings, } @@ -3016,6 +3017,7 @@ impl CheckSettings { isolated, python, ty_version, + show_version, no_project, installer, build, @@ -3082,6 +3084,7 @@ impl CheckSettings { refresh: Refresh::from(refresh), settings, ty_version, + show_version, no_project, malware_settings, } diff --git a/crates/uv/tests/project/check.rs b/crates/uv/tests/project/check.rs index af65418918b84..e521bed56bbd4 100644 --- a/crates/uv/tests/project/check.rs +++ b/crates/uv/tests/project/check.rs @@ -65,8 +65,7 @@ fn check_uses_ty_from_environment() -> Result<()> { .arg("--no-project") .arg("--ty-version") .arg(">=999.0.0") - .arg("--verbose") - .env(EnvVars::RUST_LOG, "uv::commands::project::check::ty=debug") + .arg("--show-version") .env(EnvVars::TY, ty.as_os_str()), @" success: true @@ -76,7 +75,7 @@ fn check_uses_ty_from_environment() -> Result<()> { ----- stderr ----- warning: `uv check` is experimental and may change without warning. Pass `--preview-features check-command` to disable this warning. - DEBUG Using `ty 0.0.17` + Using ty 0.0.17 " ); @@ -210,15 +209,17 @@ fn check_ty_version_no_match() { } #[test] -fn check_ty_version_pinned_verbose() -> Result<()> { - let context = uv_test::test_context_with_versions!(&[]); +fn check_ty_version_show_version() -> Result<()> { + let context = uv_test::test_context_with_versions!(&[]).with_filter(( + r"(?m)^WARN Failed to fetch `ty` from .+; falling back to .+\n", + "", + )); let main_py = context.temp_dir.child("main.py"); main_py.write_str(indoc! {r" x: int = 1 "})?; - // Narrow verbose logging to the version selection this test exercises. uv_snapshot!( context.filters(), context @@ -226,8 +227,7 @@ fn check_ty_version_pinned_verbose() -> Result<()> { .arg("--no-project") .arg("--ty-version") .arg("0.0.17") - .arg("--verbose") - .env(EnvVars::RUST_LOG, "uv::commands::project::check::ty=debug"), + .arg("--show-version"), @" success: true exit_code: 0 @@ -236,8 +236,7 @@ fn check_ty_version_pinned_verbose() -> Result<()> { ----- stderr ----- warning: `uv check` is experimental and may change without warning. Pass `--preview-features check-command` to disable this warning. - DEBUG `--exclude-newer` is ignored for pinned version `0.0.17` - DEBUG Using `ty==0.0.17` + Using ty 0.0.17 " );