mirror of
https://github.com/astral-sh/setup-uv.git
synced 2025-12-23 11:01:03 +00:00
Cache python installs (#621)
This pull request introduces support for caching Python installs in the GitHub Action, allowing users to cache not only dependencies but also the Python interpreter itself. This works by setting the `UV_PYTHON_INSTALL_DIR` to a subdirectory of the dependency cache path so that Python installs are directed there. Fixes #135 --------- Co-authored-by: Kevin Stillhammer <kevin.stillhammer@gmail.com>
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
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");
|
||||
@@ -15,6 +16,7 @@ export const cacheSuffix = core.getInput("cache-suffix") || "";
|
||||
export const cacheLocalPath = getCacheLocalPath();
|
||||
export const cacheDependencyGlob = getCacheDependencyGlob();
|
||||
export const pruneCache = core.getInput("prune-cache") === "true";
|
||||
export const cachePython = core.getInput("cache-python") === "true";
|
||||
export const ignoreNothingToCache =
|
||||
core.getInput("ignore-nothing-to-cache") === "true";
|
||||
export const ignoreEmptyWorkdir =
|
||||
@@ -123,6 +125,25 @@ function getCacheDirFromConfig(): string | undefined {
|
||||
return undefined;
|
||||
}
|
||||
|
||||
export async function getUvPythonDir(): Promise<string> {
|
||||
if (process.env.UV_PYTHON_INSTALL_DIR !== undefined) {
|
||||
core.info(
|
||||
`Using UV_PYTHON_INSTALL_DIR from environment: ${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}`,
|
||||
);
|
||||
}
|
||||
const dir = result.stdout.trim();
|
||||
core.info(`Determined uv python dir: ${dir}`);
|
||||
return dir;
|
||||
}
|
||||
|
||||
function getCacheDependencyGlob(): string {
|
||||
const cacheDependencyGlobInput = core.getInput("cache-dependency-glob");
|
||||
if (cacheDependencyGlobInput !== "") {
|
||||
|
||||
Reference in New Issue
Block a user