5
0
mirror of https://github.com/astral-sh/setup-uv.git synced 2025-12-25 11:04:24 +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:
Merlin
2025-10-09 16:47:24 -04:00
committed by GitHub
parent 3495667518
commit 6d2eb15b49
8 changed files with 197 additions and 23 deletions

View File

@@ -10,7 +10,9 @@ import {
import { STATE_UV_PATH, STATE_UV_VERSION } from "./utils/constants";
import {
cacheLocalPath,
cachePython,
enableCache,
getUvPythonDir,
ignoreNothingToCache,
pruneCache as shouldPruneCache,
saveCache as shouldSaveCache,
@@ -68,8 +70,22 @@ async function saveCache(): Promise<void> {
`Cache path ${actualCachePath} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`,
);
}
const cachePaths = [actualCachePath];
if (cachePython) {
const pythonDir = await getUvPythonDir();
core.info(`Including Python cache path: ${pythonDir}`);
if (!fs.existsSync(pythonDir) && !ignoreNothingToCache) {
throw new Error(
`Python cache path ${pythonDir} does not exist on disk. This likely indicates that there are no dependencies to cache. Consider disabling the cache input if it is not needed.`,
);
}
cachePaths.push(pythonDir);
}
core.info(`Final cache paths: ${cachePaths.join(", ")}`);
try {
await cache.saveCache([actualCachePath], cacheKey);
await cache.saveCache(cachePaths, cacheKey);
core.info(`cache saved with the key: ${cacheKey}`);
} catch (e) {
if (