Skip to content

Commit 89052ad

Browse files
committed
Add support for caching uv
See https://github.com/astral-sh/uv
1 parent 871daa9 commit 89052ad

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed

dist/setup/index.js

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89595,11 +89595,13 @@ exports.getCacheDistributor = exports.PackageManagers = void 0;
8959589595
const pip_cache_1 = __importDefault(__nccwpck_require__(5546));
8959689596
const pipenv_cache_1 = __importDefault(__nccwpck_require__(238));
8959789597
const poetry_cache_1 = __importDefault(__nccwpck_require__(1993));
89598+
const uv_cache_1 = __importDefault(__nccwpck_require__(8795));
8959889599
var PackageManagers;
8959989600
(function (PackageManagers) {
8960089601
PackageManagers["Pip"] = "pip";
8960189602
PackageManagers["Pipenv"] = "pipenv";
8960289603
PackageManagers["Poetry"] = "poetry";
89604+
PackageManagers["Uv"] = "uv";
8960389605
})(PackageManagers || (exports.PackageManagers = PackageManagers = {}));
8960489606
function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) {
8960589607
switch (packageManager) {
@@ -89609,6 +89611,8 @@ function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath)
8960989611
return new pipenv_cache_1.default(pythonVersion, cacheDependencyPath);
8961089612
case PackageManagers.Poetry:
8961189613
return new poetry_cache_1.default(pythonVersion, cacheDependencyPath);
89614+
case PackageManagers.Uv:
89615+
return new uv_cache_1.default(pythonVersion, cacheDependencyPath);
8961289616
default:
8961389617
throw new Error(`Caching for '${packageManager}' is not supported`);
8961489618
}
@@ -89983,6 +89987,88 @@ class PoetryCache extends cache_distributor_1.default {
8998389987
exports["default"] = PoetryCache;
8998489988

8998589989

89990+
/***/ }),
89991+
89992+
/***/ 8795:
89993+
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
89994+
89995+
"use strict";
89996+
89997+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
89998+
if (k2 === undefined) k2 = k;
89999+
var desc = Object.getOwnPropertyDescriptor(m, k);
90000+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
90001+
desc = { enumerable: true, get: function() { return m[k]; } };
90002+
}
90003+
Object.defineProperty(o, k2, desc);
90004+
}) : (function(o, m, k, k2) {
90005+
if (k2 === undefined) k2 = k;
90006+
o[k2] = m[k];
90007+
}));
90008+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
90009+
Object.defineProperty(o, "default", { enumerable: true, value: v });
90010+
}) : function(o, v) {
90011+
o["default"] = v;
90012+
});
90013+
var __importStar = (this && this.__importStar) || function (mod) {
90014+
if (mod && mod.__esModule) return mod;
90015+
var result = {};
90016+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
90017+
__setModuleDefault(result, mod);
90018+
return result;
90019+
};
90020+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
90021+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
90022+
return new (P || (P = Promise))(function (resolve, reject) {
90023+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
90024+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
90025+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
90026+
step((generator = generator.apply(thisArg, _arguments || [])).next());
90027+
});
90028+
};
90029+
var __importDefault = (this && this.__importDefault) || function (mod) {
90030+
return (mod && mod.__esModule) ? mod : { "default": mod };
90031+
};
90032+
Object.defineProperty(exports, "__esModule", ({ value: true }));
90033+
const glob = __importStar(__nccwpck_require__(8090));
90034+
const os = __importStar(__nccwpck_require__(2037));
90035+
const path = __importStar(__nccwpck_require__(1017));
90036+
const cache_distributor_1 = __importDefault(__nccwpck_require__(8953));
90037+
class UvCache extends cache_distributor_1.default {
90038+
constructor(pythonVersion, patterns = '**/requirements.txt') {
90039+
super('uv', patterns);
90040+
this.pythonVersion = pythonVersion;
90041+
this.patterns = patterns;
90042+
}
90043+
getCacheGlobalDirectories() {
90044+
var _a;
90045+
return __awaiter(this, void 0, void 0, function* () {
90046+
if (process.platform === 'win32') {
90047+
// `LOCALAPPDATA` should always be defined,
90048+
// but we can't just join `undefined`
90049+
// into the path in case it's not.
90050+
return [
90051+
path.join((_a = process.env['LOCALAPPDATA']) !== null && _a !== void 0 ? _a : os.homedir(), 'uv', 'cache')
90052+
];
90053+
}
90054+
return [path.join(os.homedir(), '.cache/uv')];
90055+
});
90056+
}
90057+
computeKeys() {
90058+
return __awaiter(this, void 0, void 0, function* () {
90059+
const hash = yield glob.hashFiles(this.patterns);
90060+
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
90061+
const restoreKey = undefined;
90062+
return {
90063+
primaryKey,
90064+
restoreKey
90065+
};
90066+
});
90067+
}
90068+
}
90069+
exports["default"] = UvCache;
90070+
90071+
8998690072
/***/ }),
8998790073

8998890074
/***/ 8040:

src/cache-distributions/cache-factory.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
import PipCache from './pip-cache';
22
import PipenvCache from './pipenv-cache';
33
import PoetryCache from './poetry-cache';
4+
import UvCache from './uv-cache';
45

56
export enum PackageManagers {
67
Pip = 'pip',
78
Pipenv = 'pipenv',
8-
Poetry = 'poetry'
9+
Poetry = 'poetry',
10+
Uv = 'uv'
911
}
1012

1113
export function getCacheDistributor(
@@ -20,6 +22,8 @@ export function getCacheDistributor(
2022
return new PipenvCache(pythonVersion, cacheDependencyPath);
2123
case PackageManagers.Poetry:
2224
return new PoetryCache(pythonVersion, cacheDependencyPath);
25+
case PackageManagers.Uv:
26+
return new UvCache(pythonVersion, cacheDependencyPath);
2327
default:
2428
throw new Error(`Caching for '${packageManager}' is not supported`);
2529
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import * as glob from '@actions/glob';
2+
import * as os from 'os';
3+
import * as path from 'path';
4+
5+
import CacheDistributor from './cache-distributor';
6+
7+
export default class UvCache extends CacheDistributor {
8+
constructor(
9+
private pythonVersion: string,
10+
protected patterns: string = '**/requirements.txt'
11+
) {
12+
super('uv', patterns);
13+
}
14+
15+
protected async getCacheGlobalDirectories() {
16+
if (process.platform === 'win32') {
17+
// `LOCALAPPDATA` should always be defined,
18+
// but we can't just join `undefined`
19+
// into the path in case it's not.
20+
return [
21+
path.join(process.env['LOCALAPPDATA'] ?? os.homedir(), 'uv', 'cache')
22+
];
23+
}
24+
return [path.join(os.homedir(), '.cache/uv')];
25+
}
26+
27+
protected async computeKeys() {
28+
const hash = await glob.hashFiles(this.patterns);
29+
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
30+
const restoreKey = undefined;
31+
return {
32+
primaryKey,
33+
restoreKey
34+
};
35+
}
36+
}

0 commit comments

Comments
 (0)