mirror of
https://github.com/astral-sh/uv
synced 2026-06-21 13:47:25 +00:00
Add hidden --show-version to uv check (#19892)
## Summary Adds hidden `uv check --show-version` support, matching the existing `uv format --show-version` convention. The flag now reports `Using ty <version>` for both `TY` executable overrides and resolved/downloaded ty binaries, without relying on debug logging or the separate lock-pinning work. This threads the hidden flag through CLI/settings/check execution and updates focused integration coverage for both version-selection paths.
This commit is contained in:
committed by
GitHub
parent
b08e2151b2
commit
0370ed4913
@@ -5388,6 +5388,10 @@ pub struct CheckArgs {
|
||||
#[arg(long, value_hint = ValueHint::Other)]
|
||||
pub ty_version: Option<String>,
|
||||
|
||||
/// 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
|
||||
|
||||
@@ -49,6 +49,7 @@ pub(crate) async fn check(
|
||||
install_mirrors: PythonInstallMirrors,
|
||||
settings: ResolverInstallerSettings,
|
||||
ty_version: Option<String>,
|
||||
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,
|
||||
|
||||
@@ -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<String>,
|
||||
exclude_newer: Option<jiff::Timestamp>,
|
||||
show_version: bool,
|
||||
client_builder: &BaseClientBuilder<'_>,
|
||||
cache: &Cache,
|
||||
printer: Printer,
|
||||
) -> Result<ExitStatus> {
|
||||
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,
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -2986,6 +2986,7 @@ pub(crate) struct CheckSettings {
|
||||
pub(crate) refresh: Refresh,
|
||||
pub(crate) settings: ResolverInstallerSettings,
|
||||
pub(crate) ty_version: Option<String>,
|
||||
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,
|
||||
}
|
||||
|
||||
@@ -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
|
||||
"
|
||||
);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user