mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-09-21 12:28:49 +00:00
Expose a Python "identity" output (#1036)
https://github.com/pyca/cryptography/pull/15572#discussion_r3913508686 has the context for this: TL;DR our current `python-version` output mirrors the "request" version exactly, which means that it's insufficient for any downstream that needs to manage its own cache keys (since caches shouldn't be shared across release candidates, but the `uv python` request version doesn't include RC numbers). The first commit here was my attempt to fix this by exposing the runtime Python version, but this too is imprecise: the runtime version doesn't indicate the interpreter variant (e.g. freethreading), which is also important to capture in the cache identity. My solution here is to expose `python-runtime-id`, which is just the `key` of the active Python version from `uv python list --output-format=json`. --------- Signed-off-by: William Woodruff <william@yossarian.net>
This commit is contained in:
+43
-8
@@ -10833,7 +10833,7 @@ var require_mock_interceptor = __commonJS({
|
||||
var require_mock_client = __commonJS({
|
||||
"node_modules/@actions/http-client/node_modules/undici/lib/mock/mock-client.js"(exports2, module2) {
|
||||
"use strict";
|
||||
var { promisify: promisify5 } = require("node:util");
|
||||
var { promisify: promisify6 } = require("node:util");
|
||||
var Client = require_client();
|
||||
var { buildMockDispatch } = require_mock_utils();
|
||||
var {
|
||||
@@ -10873,7 +10873,7 @@ var require_mock_client = __commonJS({
|
||||
return new MockInterceptor(opts, this[kDispatches]);
|
||||
}
|
||||
async [kClose]() {
|
||||
await promisify5(this[kOriginalClose])();
|
||||
await promisify6(this[kOriginalClose])();
|
||||
this[kConnected] = 0;
|
||||
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
||||
}
|
||||
@@ -10886,7 +10886,7 @@ var require_mock_client = __commonJS({
|
||||
var require_mock_pool = __commonJS({
|
||||
"node_modules/@actions/http-client/node_modules/undici/lib/mock/mock-pool.js"(exports2, module2) {
|
||||
"use strict";
|
||||
var { promisify: promisify5 } = require("node:util");
|
||||
var { promisify: promisify6 } = require("node:util");
|
||||
var Pool = require_pool();
|
||||
var { buildMockDispatch } = require_mock_utils();
|
||||
var {
|
||||
@@ -10926,7 +10926,7 @@ var require_mock_pool = __commonJS({
|
||||
return new MockInterceptor(opts, this[kDispatches]);
|
||||
}
|
||||
async [kClose]() {
|
||||
await promisify5(this[kOriginalClose])();
|
||||
await promisify6(this[kOriginalClose])();
|
||||
this[kConnected] = 0;
|
||||
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
||||
}
|
||||
@@ -43099,7 +43099,7 @@ var require_mock_interceptor2 = __commonJS({
|
||||
var require_mock_client2 = __commonJS({
|
||||
"node_modules/undici/lib/mock/mock-client.js"(exports2, module2) {
|
||||
"use strict";
|
||||
var { promisify: promisify5 } = require("node:util");
|
||||
var { promisify: promisify6 } = require("node:util");
|
||||
var Client = require_client2();
|
||||
var { buildMockDispatch } = require_mock_utils2();
|
||||
var {
|
||||
@@ -43147,7 +43147,7 @@ var require_mock_client2 = __commonJS({
|
||||
this[kDispatches] = [];
|
||||
}
|
||||
async [kClose]() {
|
||||
await promisify5(this[kOriginalClose])();
|
||||
await promisify6(this[kOriginalClose])();
|
||||
this[kConnected] = 0;
|
||||
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
||||
}
|
||||
@@ -43360,7 +43360,7 @@ var require_mock_call_history = __commonJS({
|
||||
var require_mock_pool2 = __commonJS({
|
||||
"node_modules/undici/lib/mock/mock-pool.js"(exports2, module2) {
|
||||
"use strict";
|
||||
var { promisify: promisify5 } = require("node:util");
|
||||
var { promisify: promisify6 } = require("node:util");
|
||||
var Pool = require_pool2();
|
||||
var { buildMockDispatch } = require_mock_utils2();
|
||||
var {
|
||||
@@ -43408,7 +43408,7 @@ var require_mock_pool2 = __commonJS({
|
||||
this[kDispatches] = [];
|
||||
}
|
||||
async [kClose]() {
|
||||
await promisify5(this[kOriginalClose])();
|
||||
await promisify6(this[kOriginalClose])();
|
||||
this[kConnected] = 0;
|
||||
this[kMockAgent][Symbols.kClients].delete(this[kOrigin]);
|
||||
}
|
||||
@@ -102102,6 +102102,40 @@ function getResolutionStrategy() {
|
||||
);
|
||||
}
|
||||
|
||||
// src/utils/python-runtime.ts
|
||||
var import_node_child_process = require("node:child_process");
|
||||
var import_node_util4 = require("node:util");
|
||||
var execFileAsync = (0, import_node_util4.promisify)(import_node_child_process.execFile);
|
||||
async function getPythonRuntimeId(inputs) {
|
||||
if (!inputs.activateEnvironment) {
|
||||
return "";
|
||||
}
|
||||
try {
|
||||
const { stdout } = await execFileAsync(
|
||||
"uv",
|
||||
[
|
||||
"python",
|
||||
"list",
|
||||
inputs.venvPath,
|
||||
"--only-installed",
|
||||
"--output-format",
|
||||
"json"
|
||||
],
|
||||
{ encoding: "utf8" }
|
||||
);
|
||||
const pythons = JSON.parse(stdout);
|
||||
if (!Array.isArray(pythons) || pythons.length !== 1 || typeof pythons[0]?.key !== "string" || pythons[0].key === "") {
|
||||
throw new Error("Expected one installed Python with a runtime key");
|
||||
}
|
||||
return pythons[0].key;
|
||||
} catch (error2) {
|
||||
throw new Error(
|
||||
`Failed to identify the activated environment's Python runtime: ${error2 instanceof Error ? error2.message : String(error2)}`,
|
||||
{ cause: error2 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// src/setup-uv.ts
|
||||
var sourceDir = __dirname;
|
||||
function formatUnexpectedFailure(error2) {
|
||||
@@ -102172,6 +102206,7 @@ async function run() {
|
||||
info2(`Successfully installed uv version ${setupResult.version}`);
|
||||
const detectedPythonVersion = await getPythonVersion2(inputs);
|
||||
setOutput("python-version", detectedPythonVersion);
|
||||
setOutput("python-runtime-id", await getPythonRuntimeId(inputs));
|
||||
if (inputs.enableCache) {
|
||||
await restoreCache2(inputs, detectedPythonVersion);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user