mirror of
https://github.com/astral-sh/setup-uv.git
synced 2026-09-04 14:39:28 +00:00
Add resolved Python version output for activated environments
This commit is contained in:
@@ -16,6 +16,7 @@ import {
|
||||
getPlatform,
|
||||
type Platform,
|
||||
} from "./utils/platforms";
|
||||
import { getResolvedPythonVersion } from "./utils/python-version";
|
||||
import { resolveUvVersion } from "./version/resolve";
|
||||
|
||||
const sourceDir = __dirname;
|
||||
@@ -101,6 +102,10 @@ async function run(): Promise<void> {
|
||||
|
||||
const detectedPythonVersion = await getPythonVersion(inputs);
|
||||
core.setOutput("python-version", detectedPythonVersion);
|
||||
core.setOutput(
|
||||
"python-version-resolved",
|
||||
await getResolvedPythonVersion(inputs),
|
||||
);
|
||||
|
||||
if (inputs.enableCache) {
|
||||
await restoreCache(inputs, detectedPythonVersion);
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
import { join } from "node:path";
|
||||
import * as core from "@actions/core";
|
||||
import * as exec from "@actions/exec";
|
||||
import type { SetupInputs } from "./inputs";
|
||||
|
||||
export async function getResolvedPythonVersion(
|
||||
inputs: SetupInputs,
|
||||
): Promise<string> {
|
||||
if (!inputs.activateEnvironment) {
|
||||
return "";
|
||||
}
|
||||
|
||||
const pythonPath =
|
||||
process.platform === "win32"
|
||||
? join(inputs.venvPath, "Scripts", "python.exe")
|
||||
: join(inputs.venvPath, "bin", "python");
|
||||
|
||||
try {
|
||||
// @actions/exec parses the executable as a command line, so quote the path.
|
||||
const { stdout } = await exec.getExecOutput(
|
||||
`"${pythonPath.replace(/"/g, '\\"')}"`,
|
||||
["-I", "-c", "import platform; print(platform.python_version())"],
|
||||
{ silent: !core.isDebug() },
|
||||
);
|
||||
return stdout.trim();
|
||||
} catch (error) {
|
||||
core.debug(
|
||||
`Failed to get the activated environment's Python version. Error: ${error instanceof Error ? error.message : String(error)}`,
|
||||
);
|
||||
return "";
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user