forked from actions/setup-python
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpip-cache.ts
52 lines (40 loc) · 1.39 KB
/
pip-cache.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
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(
private pythonVersion: string,
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']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
const restoreKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}`;
return {
primaryKey,
restoreKey: [restoreKey]
};
}
}
export default PipCache;