mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-11-22 00:05:59 +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
@@ -169,7 +169,7 @@ async function findHighestSatisfyingVersion(
|
||||
): Promise<string | undefined> {
|
||||
// This fast path assumes uv releases are semver-monotonic: newer manifest
|
||||
// entries always have higher versions, with no lower-version backports.
|
||||
const semverRange = isCompatibleReleaseSpecifier(versionSpecifier)
|
||||
const semverRange = isPep440Specifier(versionSpecifier)
|
||||
? null
|
||||
: semver.validRange(versionSpecifier);
|
||||
if (semverRange !== null) {
|
||||
@@ -196,19 +196,20 @@ async function findHighestSatisfyingVersion(
|
||||
}
|
||||
|
||||
/**
|
||||
* `~=` is the PEP 440 compatible release operator. semver accepts it as a
|
||||
* tilde range with a narrower upper bound (`~=0.5` as `<0.6.0` instead of
|
||||
* `<1.0`), so it must only be evaluated as PEP 440.
|
||||
* Specifiers that are valid PEP 440 must be evaluated as PEP 440. semver
|
||||
* accepts several of them with different semantics, e.g. `~=0.5` as `<0.6.0`
|
||||
* instead of `<1.0`, `<=0.5` as `<0.6.0` instead of `<=0.5.0` and `>0.5` as
|
||||
* `>=0.6.0` instead of `>0.5.0`.
|
||||
*/
|
||||
function isCompatibleReleaseSpecifier(versionSpecifier: string): boolean {
|
||||
return versionSpecifier.includes("~=");
|
||||
function isPep440Specifier(versionSpecifier: string): boolean {
|
||||
return pep440.validRange(versionSpecifier);
|
||||
}
|
||||
|
||||
function maxSatisfying(
|
||||
versions: string[],
|
||||
version: string,
|
||||
): string | undefined {
|
||||
const maxSemver = isCompatibleReleaseSpecifier(version)
|
||||
const maxSemver = isPep440Specifier(version)
|
||||
? ""
|
||||
: tc.evaluateVersions(versions, version);
|
||||
if (maxSemver !== "") {
|
||||
@@ -231,7 +232,7 @@ function minSatisfying(
|
||||
versions: string[],
|
||||
version: string,
|
||||
): string | undefined {
|
||||
const minSemver = isCompatibleReleaseSpecifier(version)
|
||||
const minSemver = isPep440Specifier(version)
|
||||
? null
|
||||
: semver.minSatisfying(versions, version);
|
||||
if (minSemver !== null) {
|
||||
|
||||
@@ -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