Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions crates/uv/src/commands/project/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -387,6 +388,7 @@ pub(crate) async fn check(
venv_path.as_deref(),
workspace_metadata,
exclude_newer,
show_version,
&client_builder,
cache,
printer,
Expand Down
11 changes: 9 additions & 2 deletions crates/uv/src/commands/project/check/ty.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::fmt::Write;
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::str::FromStr;
Expand Down Expand Up @@ -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()
Expand All @@ -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 {
Expand Down Expand Up @@ -123,6 +126,10 @@ pub(super) async fn run(
}
};

if show_version {
writeln!(printer.stderr(), "Using ty {}", resolved.version)?;
}

bin_install(
Binary::Ty,
&resolved,
Expand Down
1 change: 1 addition & 0 deletions crates/uv/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
3 changes: 3 additions & 0 deletions crates/uv/src/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -3016,6 +3017,7 @@ impl CheckSettings {
isolated,
python,
ty_version,
show_version,
no_project,
installer,
build,
Expand Down Expand Up @@ -3082,6 +3084,7 @@ impl CheckSettings {
refresh: Refresh::from(refresh),
settings,
ty_version,
show_version,
no_project,
malware_settings,
}
Expand Down
19 changes: 9 additions & 10 deletions crates/uv/tests/project/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
"
);

Expand Down Expand Up @@ -210,24 +209,25 @@ 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
.check()
.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
Expand All @@ -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
"
);

Expand Down