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
5 changes: 4 additions & 1 deletion crates/uv-settings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,6 +714,8 @@ impl EnvFlag {
/// the CLI level, however there are limited semantics in that context.
#[derive(Debug, Clone)]
pub struct EnvironmentOptions {
pub ruff_path: Option<PathBuf>,
pub ty_path: Option<PathBuf>,
pub skip_wheel_filename_check: Option<bool>,
pub hide_build_output: Option<bool>,
pub python_install_bin: Option<bool>,
Expand Down Expand Up @@ -788,6 +790,8 @@ impl EnvironmentOptions {
.map(Duration::from_secs);

Ok(Self {
ruff_path: parse_path_environment_variable(EnvVars::RUFF),
ty_path: parse_path_environment_variable(EnvVars::TY),
skip_wheel_filename_check: parse_boolish_environment_variable(
EnvVars::UV_SKIP_WHEEL_FILENAME_CHECK,
)?,
Expand Down Expand Up @@ -1037,7 +1041,6 @@ where
}
}

#[cfg(feature = "tracing-durations-export")]
/// Parse a path environment variable.
fn parse_path_environment_variable(name: &'static str) -> Option<PathBuf> {
let value = std::env::var_os(name)?;
Expand Down
8 changes: 8 additions & 0 deletions crates/uv-static/src/env_vars.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ impl EnvVars {
#[attr_added_in("0.6.0")]
pub const UV: &'static str = "UV";

/// The path to the Ruff binary used by `uv format`.
#[attr_added_in("next release")]
pub const RUFF: &'static str = "RUFF";

/// The path to the ty binary used by `uv check`.
#[attr_added_in("next release")]
pub const TY: &'static str = "TY";

/// Equivalent to the `--offline` command-line argument. If set, uv will disable network access.
#[attr_added_in("0.5.9")]
pub const UV_OFFLINE: &'static str = "UV_OFFLINE";
Expand Down
4 changes: 3 additions & 1 deletion crates/uv/src/commands/project/check.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};

use anyhow::Result;
use tracing::debug;
Expand Down Expand Up @@ -38,6 +38,7 @@ mod ty;
#[expect(clippy::fn_params_excessive_bools)]
pub(crate) async fn check(
project_dir: &Path,
ty_path: Option<PathBuf>,
lock_check: LockCheck,
frozen: Option<FrozenSource>,
no_sync: bool,
Expand Down Expand Up @@ -381,6 +382,7 @@ pub(crate) async fn check(

ty::run(
ty_version,
ty_path,
&target_dir,
venv_path.as_deref(),
workspace_metadata,
Expand Down
151 changes: 86 additions & 65 deletions crates/uv/src/commands/project/check/ty.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::path::Path;
use std::path::{Path, PathBuf};
use std::process::Stdio;
use std::str::FromStr;
use std::time::Duration;
Expand Down Expand Up @@ -37,6 +37,7 @@ async fn write_workspace_metadata(mut stdin: ChildStdin, workspace_metadata: Str
/// Run a type check powered by ty.
pub(super) async fn run(
version: Option<String>,
ty_path: Option<PathBuf>,
target_dir: &Path,
venv_path: Option<&Path>,
workspace_metadata: Option<String>,
Expand All @@ -45,74 +46,94 @@ pub(super) async fn run(
cache: &Cache,
printer: Printer,
) -> Result<ExitStatus> {
let retry_policy = client_builder.retry_policy();
let ty_client = client_builder.clone().retries(0).build()?;
let ty_path = if let Some(ty_path) = ty_path {
if tracing::enabled!(tracing::Level::DEBUG) {
let output = Command::new(&ty_path)
.arg("--version")
.output()
.await
.context("Failed to query ty version")?;
if !output.status.success() {
anyhow::bail!("Failed to query ty version");
}
debug!("Using `{}`", String::from_utf8_lossy(&output.stdout).trim());
}
ty_path
} else {
let retry_policy = client_builder.retry_policy();
let ty_client = client_builder.clone().retries(0).build()?;

let reporter = BinaryDownloadReporter::single(printer);
let bin_version = version
.as_deref()
.map(BinVersion::from_str)
.transpose()?
.unwrap_or(BinVersion::Default);
let reporter = BinaryDownloadReporter::single(printer);
let bin_version = version
.as_deref()
.map(BinVersion::from_str)
.transpose()?
.unwrap_or(BinVersion::Default);

let resolved = match bin_version {
BinVersion::Default => {
let constraints = Binary::Ty.default_constraints();
let resolved = find_matching_version(
Binary::Ty,
Some(&constraints),
exclude_newer,
&ty_client,
&retry_policy,
)
.await
.with_context(|| {
format!("Failed to find ty version matching default constraints: {constraints}")
})?;
debug!("Resolved `ty@{constraints}` to `ty=={}`", resolved.version);
resolved
}
BinVersion::Pinned(version) => {
if exclude_newer.is_some() {
debug!("`--exclude-newer` is ignored for pinned version `{version}`");
let resolved = match bin_version {
BinVersion::Default => {
let constraints = Binary::Ty.default_constraints();
let resolved = find_matching_version(
Binary::Ty,
Some(&constraints),
exclude_newer,
&ty_client,
&retry_policy,
)
.await
.with_context(|| {
format!("Failed to find ty version matching default constraints: {constraints}")
})?;
debug!("Resolved `ty@{constraints}` to `ty=={}`", resolved.version);
resolved
}
let resolved = ResolvedVersion::from_version(Binary::Ty, version)?;
debug!("Using `ty=={}`", resolved.version);
resolved
}
BinVersion::Latest => {
let resolved =
find_matching_version(Binary::Ty, None, exclude_newer, &ty_client, &retry_policy)
.await
.with_context(|| "Failed to find latest ty version")?;
debug!("Resolved `ty@latest` to `ty=={}`", resolved.version);
resolved
}
BinVersion::Constraint(constraints) => {
let resolved = find_matching_version(
Binary::Ty,
Some(&constraints),
exclude_newer,
&ty_client,
&retry_policy,
)
.await
.with_context(|| format!("Failed to find ty version matching: {constraints}"))?;
debug!("Resolved `ty@{constraints}` to `ty=={}`", resolved.version);
resolved
}
};
BinVersion::Pinned(version) => {
if exclude_newer.is_some() {
debug!("`--exclude-newer` is ignored for pinned version `{version}`");
}
let resolved = ResolvedVersion::from_version(Binary::Ty, version)?;
debug!("Using `ty=={}`", resolved.version);
resolved
}
BinVersion::Latest => {
let resolved = find_matching_version(
Binary::Ty,
None,
exclude_newer,
&ty_client,
&retry_policy,
)
.await
.with_context(|| "Failed to find latest ty version")?;
debug!("Resolved `ty@latest` to `ty=={}`", resolved.version);
resolved
}
BinVersion::Constraint(constraints) => {
let resolved = find_matching_version(
Binary::Ty,
Some(&constraints),
exclude_newer,
&ty_client,
&retry_policy,
)
.await
.with_context(|| format!("Failed to find ty version matching: {constraints}"))?;
debug!("Resolved `ty@{constraints}` to `ty=={}`", resolved.version);
resolved
}
};

let ty_path = bin_install(
Binary::Ty,
&resolved,
&ty_client,
&retry_policy,
cache,
&reporter,
)
.await
.with_context(|| format!("Failed to install ty {}", resolved.version))?;
bin_install(
Binary::Ty,
&resolved,
&ty_client,
&retry_policy,
cache,
&reporter,
)
.await
.with_context(|| format!("Failed to install ty {}", resolved.version))?
};

let mut command = Command::new(&ty_path);
command.current_dir(target_dir);
Expand Down
Loading
Loading