Fix uv step (#1121)
This commit is contained in:
@@ -1316,20 +1316,32 @@ pub fn run_uv(ctx: &ExecutionContext) -> Result<()> {
|
||||
.execute(&uv_exec)
|
||||
.arg("--version")
|
||||
.output_checked_utf8()?;
|
||||
// example output: "uv 0.5.11 (c4d0caaee 2024-12-19)\n"
|
||||
// Multiple possible output formats are possible according to uv source code
|
||||
//
|
||||
// https://github.com/astral-sh/uv/blob/6b7f60c1eaa840c2e933a0fb056ab46f99c991a5/crates/uv-cli/src/version.rs#L28-L42
|
||||
//
|
||||
// For example:
|
||||
// "uv 0.5.11 (c4d0caaee 2024-12-19)\n"
|
||||
// "uv 0.5.11+1 (xxxd0cee 2024-12-20)\n"
|
||||
// "uv 0.6.14\n"
|
||||
|
||||
let uv_version_output_stdout = uv_version_output.stdout;
|
||||
|
||||
let version_str = {
|
||||
// trim the starting "uv" and " " (whitespace)
|
||||
// Trim the starting "uv" and " " (whitespace)
|
||||
let start_trimmed = uv_version_output_stdout
|
||||
.trim_start_matches("uv")
|
||||
.trim_start_matches(' ');
|
||||
// remove the tailing part " (c4d0caaee 2024-12-19)\n"
|
||||
let first_whitespace_index = start_trimmed
|
||||
.find(' ')
|
||||
.expect("the output of `uv --version` changed, please file an issue to Topgrade");
|
||||
// this should be our version str "0.5.11"
|
||||
&start_trimmed[..first_whitespace_index]
|
||||
// Remove the tailing part " (c4d0caaee 2024-12-19)\n", if it's there
|
||||
match start_trimmed.find(' ') {
|
||||
None => start_trimmed.trim_end_matches('\n'), // Otherwise, just strip the newline
|
||||
Some(i) => &start_trimmed[..i],
|
||||
}
|
||||
|
||||
// After trimming, it should be a string in 2 possible formats, both can be handled by `Version::parse()`
|
||||
//
|
||||
// 1. "0.5.11"
|
||||
// 2. "0.5.11+1"
|
||||
};
|
||||
let version =
|
||||
Version::parse(version_str).expect("the output of `uv --version` changed, please file an issue to Topgrade");
|
||||
|
||||
Reference in New Issue
Block a user