Add value of UV_PYTHON_INSTALL_DIR to path (#628)

Closes: #610
This commit is contained in:
Kevin Stillhammer
2025-10-11 18:42:06 +02:00
committed by GitHub
parent bd1f875aba
commit d18bcc753a
7 changed files with 112 additions and 49 deletions

View File

@@ -7,8 +7,8 @@ import {
cacheLocalPath,
cachePython,
cacheSuffix,
getUvPythonDir,
pruneCache,
pythonDir,
pythonVersion as pythonVersionInput,
restoreCache as shouldRestoreCache,
workingDirectory,
@@ -34,7 +34,7 @@ export async function restoreCache(): Promise<void> {
);
const cachePaths = [cacheLocalPath];
if (cachePython) {
cachePaths.push(await getUvPythonDir());
cachePaths.push(pythonDir);
}
try {
matchedKey = await cache.restoreCache(cachePaths, cacheKey);

View File

@@ -12,8 +12,8 @@ import {
cacheLocalPath,
cachePython,
enableCache,
getUvPythonDir,
ignoreNothingToCache,
pythonDir,
pruneCache as shouldPruneCache,
saveCache as shouldSaveCache,
} from "./utils/inputs";
@@ -73,7 +73,6 @@ async function saveCache(): Promise<void> {
const cachePaths = [actualCachePath];
if (cachePython) {
const pythonDir = await getUvPythonDir();
core.info(`Including Python cache path: ${pythonDir}`);
if (!fs.existsSync(pythonDir) && !ignoreNothingToCache) {
throw new Error(

View File

@@ -19,6 +19,7 @@ import {
githubToken,
ignoreEmptyWorkdir,
manifestFile,
pythonDir,
pythonVersion,
toolBinDir,
toolDir,
@@ -51,6 +52,7 @@ async function run(): Promise<void> {
addToolBinToPath();
addUvToPathAndOutput(setupResult.uvDir);
setToolDir();
addPythonDirToPath();
setupPython();
await activateEnvironment();
addMatchers();
@@ -194,6 +196,17 @@ function setToolDir(): void {
}
}
function addPythonDirToPath(): void {
core.exportVariable("UV_PYTHON_INSTALL_DIR", pythonDir);
core.info(`Set UV_PYTHON_INSTALL_DIR to ${pythonDir}`);
if (process.env.UV_NO_MODIFY_PATH !== undefined) {
core.info("UV_NO_MODIFY_PATH is set, not adding python dir to path");
} else {
core.addPath(pythonDir);
core.info(`Added ${pythonDir} to the path`);
}
}
function setupPython(): void {
if (pythonVersion !== "") {
core.exportVariable("UV_PYTHON", pythonVersion);

View File

@@ -1,6 +1,5 @@
import path from "node:path";
import * as core from "@actions/core";
import * as exec from "@actions/exec";
import { getConfigValueFromTomlFile } from "./config-file";
export const workingDirectory = core.getInput("working-directory");
@@ -23,6 +22,7 @@ export const ignoreEmptyWorkdir =
core.getInput("ignore-empty-workdir") === "true";
export const toolBinDir = getToolBinDir();
export const toolDir = getToolDir();
export const pythonDir = getUvPythonDir();
export const githubToken = core.getInput("github-token");
export const manifestFile = getManifestFile();
export const addProblemMatchers =
@@ -125,23 +125,26 @@ function getCacheDirFromConfig(): string | undefined {
return undefined;
}
export async function getUvPythonDir(): Promise<string> {
export function getUvPythonDir(): string {
if (process.env.UV_PYTHON_INSTALL_DIR !== undefined) {
core.info(
`Using UV_PYTHON_INSTALL_DIR from environment: ${process.env.UV_PYTHON_INSTALL_DIR}`,
`UV_PYTHON_INSTALL_DIR is already set to ${process.env.UV_PYTHON_INSTALL_DIR}`,
);
return process.env.UV_PYTHON_INSTALL_DIR;
}
core.info("Determining uv python dir using `uv python dir`...");
const result = await exec.getExecOutput("uv", ["python", "dir"]);
if (result.exitCode !== 0) {
throw new Error(
`Failed to get uv python dir: ${result.stderr || result.stdout}`,
);
if (process.env.RUNNER_ENVIRONMENT !== "github-hosted") {
if (process.platform === "win32") {
return `${process.env.APPDATA}${path.sep}uv${path.sep}python`;
} else {
return `${process.env.HOME}${path.sep}.local${path.sep}share${path.sep}uv${path.sep}python`;
}
}
const dir = result.stdout.trim();
core.info(`Determined uv python dir: ${dir}`);
return dir;
if (process.env.RUNNER_TEMP !== undefined) {
return `${process.env.RUNNER_TEMP}${path.sep}uv-python-dir`;
}
throw Error(
"Could not determine UV_PYTHON_INSTALL_DIR. Please make sure RUNNER_TEMP is set or provide the UV_PYTHON_INSTALL_DIR environment variable",
);
}
function getCacheDependencyGlob(): string {