mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-28 01:16:03 +00:00
fix: resolve partial PEP 440 specifiers with PEP 440 semantics (#1128)
## Summary `<=`, `==` and `>` with a partial version are valid PEP 440 specifiers, but the resolver tries them as semver ranges first, and semver reads them differently: | specifier | semver (before) | PEP 440 (what uv enforces) | |---|---|---| | `<=0.5` | `<0.6.0`, installs 0.5.31 | `<=0.5.0`, installs 0.5.0 | | `==0.5` | `==` is stripped and `0.5` is read as `0.5.x`, installs 0.5.31 | `==0.5.0`, installs 0.5.0 | | `>0.5` with `resolution-strategy: lowest` | `>=0.6.0`, installs 0.6.0 | `>0.5.0`, installs 0.5.1 | So `required-version = "<=0.5"` or `"==0.5"` in `uv.toml` / `pyproject.toml` installs a uv that does not satisfy the project's own `required-version`, and uv refuses to run there (`Required uv version ... does not match the running version ...`). This is the same problem #1111 fixed for `~=`. Instead of adding more operators to that check, specifiers that `@renovatebot/pep440` accepts as a valid range now skip the semver evaluation, and `==` is only stripped from a full version, so `==0.5` stays a PEP 440 pin. Notes: - Semver-only syntax is not valid PEP 440 and still goes through semver: `0.4.x`, `^0.5`, `~0.5`, `>=0.4.0 <0.5.0` and a bare `0.5`. - Inputs that are valid in both, like `>=0.4.0` from the docs, now go through PEP 440. They mean the same in both, and the PEP 440 path uses the same first-match lookup over the manifest. - Full pins like `==0.9.26` still resolve as explicit versions, and compound specifiers like `>=0.4,<=0.5` already went through PEP 440. ## Test plan - Added cases for `<=0.9` and `==0.9` with the default strategy and `>0.9` with `lowest` in `download-version.test.ts`. All three fail without the change. - `npm ci --ignore-scripts`, then `npm run build`, `npm run check` (no fixes), `npm run package` and `npm run test:unit` on macOS with Node 24.13.0: 179 tests across 16 suites pass. The rebuilt `dist/setup/index.cjs` only differs in the changed functions. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
bd4d5efd86
commit
898180d41d
4 files changed
+54
-15
No files matched your search
@@ -21,8 +21,13 @@ export type ParsedVersionSpecifier =
|
||||
export function normalizeVersionSpecifier(specifier: string): string {
|
||||
const trimmedSpecifier = specifier.trim();
|
||||
|
||||
// Only strip `==` from full versions. A partial pin like `==0.5` means
|
||||
// `==0.5.0` in PEP 440, but `0.5` alone is read as the semver range `0.5.x`.
|
||||
if (trimmedSpecifier.startsWith("==")) {
|
||||
return trimmedSpecifier.slice(2);
|
||||
const pinnedVersion = trimmedSpecifier.slice(2).trim();
|
||||
if (tc.isExplicitVersion(pinnedVersion)) {
|
||||
return pinnedVersion;
|
||||
}
|
||||
}
|
||||
|
||||
return trimmedSpecifier;
|
||||
|
||||
Reference in new issue
Block a user