diff --git a/crates/uv-bin-install/src/lib.rs b/crates/uv-bin-install/src/lib.rs index b699483448d25..7813837e8b783 100644 --- a/crates/uv-bin-install/src/lib.rs +++ b/crates/uv-bin-install/src/lib.rs @@ -21,7 +21,7 @@ use uv_distribution_filename::SourceDistExtension; use uv_cache::{Cache, CacheBucket, CacheEntry, Error as CacheError}; use uv_client::{BaseClient, RetryState}; use uv_extract::{Error as ExtractError, stream}; -use uv_pep440::Version; +use uv_pep440::{Version, VersionSpecifier, VersionSpecifiers}; use uv_platform::Platform; use uv_redacted::DisplaySafeUrl; @@ -32,11 +32,19 @@ pub enum Binary { } impl Binary { - /// Get the default version for this binary. - pub fn default_version(&self) -> Version { + /// Get the default version constraints for this binary. + /// + /// Returns a version range constraint (e.g., `>=0.15,<0.16`) rather than a pinned version, + /// allowing patch version updates without requiring a uv release. + pub fn default_constraints(&self) -> VersionSpecifiers { match self { // TODO(zanieb): Figure out a nice way to automate updating this - Self::Ruff => Version::new([0, 15, 0]), + Self::Ruff => [ + VersionSpecifier::greater_than_equal_version(Version::new([0, 15])), + VersionSpecifier::less_than_version(Version::new([0, 16])), + ] + .into_iter() + .collect(), } } diff --git a/crates/uv-cli/src/lib.rs b/crates/uv-cli/src/lib.rs index 844c1b2860eb0..67a4e9aa50c28 100644 --- a/crates/uv-cli/src/lib.rs +++ b/crates/uv-cli/src/lib.rs @@ -5079,7 +5079,7 @@ pub struct FormatArgs { /// Accepts either a version (e.g., `0.8.2`) which will be treated as an exact pin, /// a version specifier (e.g., `>=0.8.0`), or `latest` to use the latest available version. /// - /// By default, a pinned version of Ruff will be used. + /// By default, a constrained version range of Ruff will be used (e.g., `>=0.15,<0.16`). #[arg(long, value_hint = ValueHint::Other)] pub version: Option, diff --git a/crates/uv-test/src/lib.rs b/crates/uv-test/src/lib.rs index 55c450660e801..9756a2f18372a 100755 --- a/crates/uv-test/src/lib.rs +++ b/crates/uv-test/src/lib.rs @@ -1288,7 +1288,7 @@ impl TestContext { command.arg("format"); self.add_shared_options(&mut command, false); // Override to a more recent date for ruff version resolution - command.env(EnvVars::UV_EXCLUDE_NEWER, "2025-01-01T00:00:00Z"); + command.env(EnvVars::UV_EXCLUDE_NEWER, "2026-03-01T00:00:00Z"); command } diff --git a/crates/uv/src/commands/project/format.rs b/crates/uv/src/commands/project/format.rs index aaa073d6849e6..94d85f37475c5 100644 --- a/crates/uv/src/commands/project/format.rs +++ b/crates/uv/src/commands/project/format.rs @@ -79,8 +79,24 @@ pub(crate) async fn format( let resolved = match bin_version { BinVersion::Default => { - // Use the default pinned version - ResolvedVersion::from_version(Binary::Ruff, Binary::Ruff.default_version())? + // Find the best version matching the default constraints + let constraints = Binary::Ruff.default_constraints(); + let resolved = find_matching_version( + Binary::Ruff, + Some(&constraints), + exclude_newer, + &client, + &retry_policy, + ) + .await + .with_context(|| { + format!("Failed to find ruff version matching default constraints: {constraints}") + })?; + debug!( + "Resolved `ruff@{constraints}` to `ruff=={}`", + resolved.version + ); + resolved } BinVersion::Pinned(version) => { // Use the exact version directly without manifest lookup. diff --git a/crates/uv/tests/it/format.rs b/crates/uv/tests/it/format.rs index 509f3a419d041..5d65dd5e29b74 100644 --- a/crates/uv/tests/it/format.rs +++ b/crates/uv/tests/it/format.rs @@ -517,7 +517,7 @@ fn format_version_constraints() -> Result<()> { ----- stderr ----- warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. - ruff 0.8.4 + ruff 0.15.0 "); Ok(()) @@ -550,7 +550,7 @@ fn format_version_latest() -> Result<()> { ----- stderr ----- warning: `uv format` is experimental and may change without warning. Pass `--preview-features format` to disable this warning. - ruff 0.8.4 + ruff 0.15.0 "); Ok(())