mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-07-03 02:49:30 +00:00
feat: support uv.lock as a version-file source
This commit is contained in:
parent
ca5ddd015e
commit
4c810afe20
9 changed files with 124 additions and 11 deletions
36
__tests__/version/uv-lock-file.test.ts
Normal file
36
__tests__/version/uv-lock-file.test.ts
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
import { describe, expect, it } from "@jest/globals";
|
||||
import { getUvVersionFromUvLockContent } from "../../src/version/uv-lock-file";
|
||||
|
||||
const UV_LOCK = `version = 1
|
||||
requires-python = ">=3.12"
|
||||
|
||||
[[package]]
|
||||
name = "anyio"
|
||||
version = "4.6.0"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
|
||||
[[package]]
|
||||
name = "uv"
|
||||
version = "0.8.17"
|
||||
source = { registry = "https://pypi.org/simple" }
|
||||
`;
|
||||
|
||||
describe("getUvVersionFromUvLockContent", () => {
|
||||
it("returns the exact uv version locked in uv.lock", () => {
|
||||
expect(getUvVersionFromUvLockContent(UV_LOCK)).toBe("0.8.17");
|
||||
});
|
||||
|
||||
it("returns undefined when uv is not a locked package", () => {
|
||||
const content = `version = 1
|
||||
|
||||
[[package]]
|
||||
name = "anyio"
|
||||
version = "4.6.0"
|
||||
`;
|
||||
expect(getUvVersionFromUvLockContent(content)).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns undefined when there are no packages", () => {
|
||||
expect(getUvVersionFromUvLockContent("version = 1\n")).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
|
@ -63,6 +63,24 @@ describe("resolveVersionRequest", () => {
|
|||
});
|
||||
});
|
||||
|
||||
it("uses the exact uv version locked in uv.lock when it is passed via version-file", () => {
|
||||
const workingDirectory = createTempProject({
|
||||
"uv.lock": `version = 1\n\n[[package]]\nname = "uv"\nversion = "0.8.17"\nsource = { registry = "https://pypi.org/simple" }\n`,
|
||||
});
|
||||
|
||||
const request = resolveVersionRequest({
|
||||
versionFile: path.join(workingDirectory, "uv.lock"),
|
||||
workingDirectory,
|
||||
});
|
||||
|
||||
expect(request).toEqual({
|
||||
format: "uv.lock",
|
||||
source: "version-file",
|
||||
sourcePath: path.join(workingDirectory, "uv.lock"),
|
||||
specifier: "0.8.17",
|
||||
});
|
||||
});
|
||||
|
||||
it("uses requirements.txt when it is passed via version-file", () => {
|
||||
const workingDirectory = createTempProject({
|
||||
"requirements.txt": "uv==0.6.17\nuvicorn==0.35.0\n",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue