mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-13 14:34:11 +02:00
Implementation of python's caching (#266)
This commit is contained in:
parent
52636cf49a
commit
280924fbef
75 changed files with 126753 additions and 7699 deletions
49
src/cache-distributions/pip-cache.ts
Normal file
49
src/cache-distributions/pip-cache.ts
Normal file
|
@ -0,0 +1,49 @@
|
|||
import * as glob from '@actions/glob';
|
||||
import * as core from '@actions/core';
|
||||
import * as exec from '@actions/exec';
|
||||
|
||||
import * as path from 'path';
|
||||
import os from 'os';
|
||||
|
||||
import CacheDistributor from './cache-distributor';
|
||||
|
||||
class PipCache extends CacheDistributor {
|
||||
constructor(cacheDependencyPath: string = '**/requirements.txt') {
|
||||
super('pip', cacheDependencyPath);
|
||||
}
|
||||
|
||||
protected async getCacheGlobalDirectories() {
|
||||
const {stdout, stderr, exitCode} = await exec.getExecOutput(
|
||||
'pip cache dir'
|
||||
);
|
||||
|
||||
if (exitCode && stderr) {
|
||||
throw new Error(
|
||||
`Could not get cache folder path for pip package manager`
|
||||
);
|
||||
}
|
||||
|
||||
let resolvedPath = stdout.trim();
|
||||
|
||||
if (resolvedPath.includes('~')) {
|
||||
resolvedPath = path.join(os.homedir(), resolvedPath.slice(1));
|
||||
}
|
||||
|
||||
core.debug(`global cache directory path is ${resolvedPath}`);
|
||||
|
||||
return [resolvedPath];
|
||||
}
|
||||
|
||||
protected async computeKeys() {
|
||||
const hash = await glob.hashFiles(this.cacheDependencyPath);
|
||||
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}-${hash}`;
|
||||
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-${this.packageManager}`;
|
||||
|
||||
return {
|
||||
primaryKey,
|
||||
restoreKey: [restoreKey]
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default PipCache;
|
Loading…
Add table
Add a link
Reference in a new issue