Add an experimental uv format command (#15017)

As a frontend to Ruff's formatter.

There are some interesting choices here, some of which may just be
temporary:

1. We pin a default version of Ruff, so `uv format` is stable for a
given uv version
2. We install Ruff from GitHub instead of PyPI, which means we don't
need a Python interpreter or environment
3. We do not read the Ruff version from the dependency tree

See https://github.com/astral-sh/ruff/pull/19665 for a prototype of the
LSP integration.
This commit is contained in:
Zanie Blue 2025-08-21 06:33:18 -05:00 committed by GitHub
parent 8d6ea3f2ea
commit e31f000da7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
22 changed files with 1110 additions and 5 deletions

View file

@ -17,6 +17,7 @@ bitflags::bitflags! {
const PACKAGE_CONFLICTS = 1 << 5;
const EXTRA_BUILD_DEPENDENCIES = 1 << 6;
const DETECT_MODULE_CONFLICTS = 1 << 7;
const FORMAT = 1 << 8;
}
}
@ -34,6 +35,7 @@ impl PreviewFeatures {
Self::PACKAGE_CONFLICTS => "package-conflicts",
Self::EXTRA_BUILD_DEPENDENCIES => "extra-build-dependencies",
Self::DETECT_MODULE_CONFLICTS => "detect-module-conflicts",
Self::FORMAT => "format",
_ => panic!("`flag_as_str` can only be used for exactly one feature flag"),
}
}
@ -79,6 +81,7 @@ impl FromStr for PreviewFeatures {
"package-conflicts" => Self::PACKAGE_CONFLICTS,
"extra-build-dependencies" => Self::EXTRA_BUILD_DEPENDENCIES,
"detect-module-conflicts" => Self::DETECT_MODULE_CONFLICTS,
"format" => Self::FORMAT,
_ => {
warn_user_once!("Unknown preview feature: `{part}`");
continue;
@ -253,6 +256,7 @@ mod tests {
PreviewFeatures::DETECT_MODULE_CONFLICTS.flag_as_str(),
"detect-module-conflicts"
);
assert_eq!(PreviewFeatures::FORMAT.flag_as_str(), "format");
}
#[test]