mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-07-07 02:00:49 +02:00
Strip environment markers from detected uv dependency pins (#938)
## Summary - strip PEP 508 environment markers before extracting uv versions from dependency entries - cover dependency-group pins with and without whitespace before the marker - cover requirements-style pins with markers Fixes #920 ## Validation - npm ci --ignore-scripts - npm run all Refs: pi-session 019f316a-4108-7975-892f-ee5bf8abc7c3
This commit is contained in:
co-authored by
GitHub
parent
17c398959b
commit
d31148d669
@@ -1,5 +1,9 @@
|
||||
import { expect, test } from "@jest/globals";
|
||||
import { getUvVersionFromFile } from "../../src/version/file-parser";
|
||||
import {
|
||||
getUvVersionFromPyprojectContent,
|
||||
getUvVersionFromRequirementsText,
|
||||
} from "../../src/version/requirements-file";
|
||||
|
||||
test("ignores dependencies starting with uv", async () => {
|
||||
const parsedVersion = getUvVersionFromFile(
|
||||
@@ -7,3 +11,24 @@ test("ignores dependencies starting with uv", async () => {
|
||||
);
|
||||
expect(parsedVersion).toBe("0.6.17");
|
||||
});
|
||||
|
||||
test.each([
|
||||
["without space before marker", "uv==0.11.20; sys_platform != 'emscripten'"],
|
||||
["with space before marker", "uv==0.11.20 ; sys_platform != 'emscripten'"],
|
||||
])("strips PEP 508 markers from pyproject dependency groups %s", (_, dependency) => {
|
||||
const parsedVersion = getUvVersionFromPyprojectContent(`[dependency-groups]
|
||||
test = [
|
||||
"${dependency}",
|
||||
]
|
||||
`);
|
||||
|
||||
expect(parsedVersion).toBe("==0.11.20");
|
||||
});
|
||||
|
||||
test("strips PEP 508 markers from requirements dependencies", () => {
|
||||
const parsedVersion = getUvVersionFromRequirementsText(
|
||||
"uv==0.11.20; sys_platform != 'emscripten'",
|
||||
);
|
||||
|
||||
expect(parsedVersion).toBe("==0.11.20");
|
||||
});
|
||||
|
||||
+5
-1
@@ -97414,7 +97414,11 @@ function parsePyprojectContent(pyprojectContent) {
|
||||
return parse4(pyprojectContent);
|
||||
}
|
||||
function getUvVersionFromAllDependencies(allDependencies) {
|
||||
return allDependencies.find((dep) => dep.match(/^uv[=<>~!]/))?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
return allDependencies.map(getUvVersionFromDependency).find((version3) => version3 !== void 0);
|
||||
}
|
||||
function getUvVersionFromDependency(dependency) {
|
||||
const dependencyWithoutMarker = dependency.split(";", 1)[0]?.trim();
|
||||
return dependencyWithoutMarker?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
}
|
||||
|
||||
// src/version/tool-versions-file.ts
|
||||
|
||||
@@ -63,7 +63,11 @@ function getUvVersionFromAllDependencies(
|
||||
allDependencies: string[],
|
||||
): string | undefined {
|
||||
return allDependencies
|
||||
.find((dep: string) => dep.match(/^uv[=<>~!]/))
|
||||
?.match(/^uv([=<>~!]+\S*)/)?.[1]
|
||||
.trim();
|
||||
.map(getUvVersionFromDependency)
|
||||
.find((version): version is string => version !== undefined);
|
||||
}
|
||||
|
||||
function getUvVersionFromDependency(dependency: string): string | undefined {
|
||||
const dependencyWithoutMarker = dependency.split(";", 1)[0]?.trim();
|
||||
return dependencyWithoutMarker?.match(/^uv([=<>~!]+\S*)/)?.[1].trim();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user