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
16 changes: 12 additions & 4 deletions crates/uv-bin-install/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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(),
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-cli/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<String>,

Expand Down
2 changes: 1 addition & 1 deletion crates/uv-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
20 changes: 18 additions & 2 deletions crates/uv/src/commands/project/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions crates/uv/tests/it/format.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Copy link
Copy Markdown
Contributor

@andersk andersk Feb 15, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These tests have broken now that 0.15.1 has been released.

");

Ok(())
Expand Down Expand Up @@ -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(())
Expand Down
Loading