3
0
Fork 0
mirror of https://gitea.com/actions/setup-python.git synced 2024-11-28 13:09:34 +01:00

Add support for caching uv

See https://github.com/astral-sh/uv
This commit is contained in:
Aarni Koskela 2024-02-19 13:30:09 +02:00
parent 871daa956c
commit 89052adf60
3 changed files with 127 additions and 1 deletions

86
dist/setup/index.js vendored
View file

@ -89595,11 +89595,13 @@ exports.getCacheDistributor = exports.PackageManagers = void 0;
const pip_cache_1 = __importDefault(__nccwpck_require__(5546)); const pip_cache_1 = __importDefault(__nccwpck_require__(5546));
const pipenv_cache_1 = __importDefault(__nccwpck_require__(238)); const pipenv_cache_1 = __importDefault(__nccwpck_require__(238));
const poetry_cache_1 = __importDefault(__nccwpck_require__(1993)); const poetry_cache_1 = __importDefault(__nccwpck_require__(1993));
const uv_cache_1 = __importDefault(__nccwpck_require__(8795));
var PackageManagers; var PackageManagers;
(function (PackageManagers) { (function (PackageManagers) {
PackageManagers["Pip"] = "pip"; PackageManagers["Pip"] = "pip";
PackageManagers["Pipenv"] = "pipenv"; PackageManagers["Pipenv"] = "pipenv";
PackageManagers["Poetry"] = "poetry"; PackageManagers["Poetry"] = "poetry";
PackageManagers["Uv"] = "uv";
})(PackageManagers || (exports.PackageManagers = PackageManagers = {})); })(PackageManagers || (exports.PackageManagers = PackageManagers = {}));
function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) { function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath) {
switch (packageManager) { switch (packageManager) {
@ -89609,6 +89611,8 @@ function getCacheDistributor(packageManager, pythonVersion, cacheDependencyPath)
return new pipenv_cache_1.default(pythonVersion, cacheDependencyPath); return new pipenv_cache_1.default(pythonVersion, cacheDependencyPath);
case PackageManagers.Poetry: case PackageManagers.Poetry:
return new poetry_cache_1.default(pythonVersion, cacheDependencyPath); return new poetry_cache_1.default(pythonVersion, cacheDependencyPath);
case PackageManagers.Uv:
return new uv_cache_1.default(pythonVersion, cacheDependencyPath);
default: default:
throw new Error(`Caching for '${packageManager}' is not supported`); throw new Error(`Caching for '${packageManager}' is not supported`);
} }
@ -89983,6 +89987,88 @@ class PoetryCache extends cache_distributor_1.default {
exports["default"] = PoetryCache; exports["default"] = PoetryCache;
/***/ }),
/***/ 8795:
/***/ (function(__unused_webpack_module, exports, __nccwpck_require__) {
"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
const glob = __importStar(__nccwpck_require__(8090));
const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017));
const cache_distributor_1 = __importDefault(__nccwpck_require__(8953));
class UvCache extends cache_distributor_1.default {
constructor(pythonVersion, patterns = '**/requirements.txt') {
super('uv', patterns);
this.pythonVersion = pythonVersion;
this.patterns = patterns;
}
getCacheGlobalDirectories() {
var _a;
return __awaiter(this, void 0, void 0, function* () {
if (process.platform === 'win32') {
// `LOCALAPPDATA` should always be defined,
// but we can't just join `undefined`
// into the path in case it's not.
return [
path.join((_a = process.env['LOCALAPPDATA']) !== null && _a !== void 0 ? _a : os.homedir(), 'uv', 'cache')
];
}
return [path.join(os.homedir(), '.cache/uv')];
});
}
computeKeys() {
return __awaiter(this, void 0, void 0, function* () {
const hash = yield glob.hashFiles(this.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = undefined;
return {
primaryKey,
restoreKey
};
});
}
}
exports["default"] = UvCache;
/***/ }), /***/ }),
/***/ 8040: /***/ 8040:

View file

@ -1,11 +1,13 @@
import PipCache from './pip-cache'; import PipCache from './pip-cache';
import PipenvCache from './pipenv-cache'; import PipenvCache from './pipenv-cache';
import PoetryCache from './poetry-cache'; import PoetryCache from './poetry-cache';
import UvCache from './uv-cache';
export enum PackageManagers { export enum PackageManagers {
Pip = 'pip', Pip = 'pip',
Pipenv = 'pipenv', Pipenv = 'pipenv',
Poetry = 'poetry' Poetry = 'poetry',
Uv = 'uv'
} }
export function getCacheDistributor( export function getCacheDistributor(
@ -20,6 +22,8 @@ export function getCacheDistributor(
return new PipenvCache(pythonVersion, cacheDependencyPath); return new PipenvCache(pythonVersion, cacheDependencyPath);
case PackageManagers.Poetry: case PackageManagers.Poetry:
return new PoetryCache(pythonVersion, cacheDependencyPath); return new PoetryCache(pythonVersion, cacheDependencyPath);
case PackageManagers.Uv:
return new UvCache(pythonVersion, cacheDependencyPath);
default: default:
throw new Error(`Caching for '${packageManager}' is not supported`); throw new Error(`Caching for '${packageManager}' is not supported`);
} }

View file

@ -0,0 +1,36 @@
import * as glob from '@actions/glob';
import * as os from 'os';
import * as path from 'path';
import CacheDistributor from './cache-distributor';
export default class UvCache extends CacheDistributor {
constructor(
private pythonVersion: string,
protected patterns: string = '**/requirements.txt'
) {
super('uv', patterns);
}
protected async getCacheGlobalDirectories() {
if (process.platform === 'win32') {
// `LOCALAPPDATA` should always be defined,
// but we can't just join `undefined`
// into the path in case it's not.
return [
path.join(process.env['LOCALAPPDATA'] ?? os.homedir(), 'uv', 'cache')
];
}
return [path.join(os.homedir(), '.cache/uv')];
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = undefined;
return {
primaryKey,
restoreKey
};
}
}