mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-05 01:35:32 +00:00
fix: allow whitespace in uv requirement specifiers (#1112)
## Summary When the uv version is read from dependencies (`requirements.txt`, or `project.dependencies` / `optional-dependencies` / `dependency-groups` in `pyproject.toml` via `version-file`), the specifier was matched with `/^uv([=<>~!]+\S*)/`. PEP 508 allows whitespace around operators and after commas, and those valid forms were misread: | dependency | before | after | |---|---|---| | `uv >= 0.5.0` | not found, latest uv installed | `>=0.5.0` | | `uv == 0.11.20` | not found, latest uv installed | `==0.11.20` | | `uv>=0.5.0, <0.6.0` | `>=0.5.0,`, fails with `No version found for >=0.5.0,` | `>=0.5.0,<0.6.0` | The regex now allows whitespace around operators and between comma-separated clauses, and strips it from the result. Inputs that worked before give the same result, including inline `--hash=` options, trailing ` # comments`, the `\` continuation lines from `uv pip compile --generate-hashes`, and names that only start with `uv` (`uvicorn`, `uv-build`). ## Test plan - Added cases for spaced operators, spaced clauses, inline `--hash` and trailing comments. The four whitespace cases failed before the change. - `npm run all` on Ubuntu (WSL) with Node 24.19.0: build, Biome (no fixes), packaging, and 165 tests across 15 suites pass. The rebuilt `dist/setup/index.cjs` only differs in the changed line. --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
80fbe0140c
commit
9c7332190c
@@ -35,3 +35,14 @@ test("strips PEP 508 markers from requirements dependencies", () => {
|
||||
|
||||
expect(parsedVersion).toBe("==0.11.20");
|
||||
});
|
||||
|
||||
test.each([
|
||||
["uv >= 0.5.0", ">=0.5.0"],
|
||||
["uv == 0.11.20", "==0.11.20"],
|
||||
["uv>=0.5.0, <0.6.0", ">=0.5.0,<0.6.0"],
|
||||
["uv >= 0.5.0 , < 0.6.0", ">=0.5.0,<0.6.0"],
|
||||
["uv==0.11.20 --hash=sha256:abc", "==0.11.20"],
|
||||
["uv==0.11.20 # pinned for CI", "==0.11.20"],
|
||||
])("allows whitespace in the uv specifier %s", (dependency, expected) => {
|
||||
expect(getUvVersionFromRequirementsText(dependency)).toBe(expected);
|
||||
});
|
||||
|
||||
+1
-1
@@ -101579,7 +101579,7 @@ function getUvVersionFromAllDependencies(allDependencies) {
|
||||
}
|
||||
function getUvVersionFromDependency(dependency) {
|
||||
const dependencyWithoutMarker = dependency.split(";", 1)[0]?.trim();
|
||||
return dependencyWithoutMarker?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
return dependencyWithoutMarker?.match(/^uv\s*((?:[=<>~!]+\s*[^\s,]+\s*,?\s*)+)/)?.[1].replace(/\s/g, "");
|
||||
}
|
||||
|
||||
// src/version/tool-versions-file.ts
|
||||
|
||||
@@ -69,5 +69,7 @@ function getUvVersionFromAllDependencies(
|
||||
|
||||
function getUvVersionFromDependency(dependency: string): string | undefined {
|
||||
const dependencyWithoutMarker = dependency.split(";", 1)[0]?.trim();
|
||||
return dependencyWithoutMarker?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
return dependencyWithoutMarker
|
||||
?.match(/^uv\s*((?:[=<>~!]+\s*[^\s,]+\s*,?\s*)+)/)?.[1]
|
||||
.replace(/\s/g, "");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user