setup-python/src/cache-distributions/pipenv-cache.ts

45 lines
1.4 KiB
TypeScript
Raw Normal View History

2021-10-27 06:52:29 +00:00
import * as glob from '@actions/glob';
import * as os from 'os';
import * as path from 'path';
import * as core from '@actions/core';
import CacheDistributor from './cache-distributor';
class PipenvCache extends CacheDistributor {
constructor(
private pythonVersion: string,
2021-11-09 07:41:35 +00:00
protected patterns: string = '**/Pipfile.lock'
2021-10-27 06:52:29 +00:00
) {
super('pipenv', patterns);
}
2021-11-09 07:41:35 +00:00
protected async getCacheGlobalDirectories() {
let virtualEnvRelativePath;
2021-11-16 13:51:44 +00:00
// Default virtualenv directories are hardcoded,
// because pipenv is not preinstalled on hosted images and virtualenv is not created:
// https://github.com/pypa/pipenv/blob/1daaa0de9a0b00d386c6baeb809d8d4ee6795cfd/pipenv/utils.py#L1990-L2002
2021-10-27 06:52:29 +00:00
if (process.platform === 'win32') {
2021-11-09 07:41:35 +00:00
virtualEnvRelativePath = '.virtualenvs';
2021-10-27 06:52:29 +00:00
} else {
2021-11-09 07:41:35 +00:00
virtualEnvRelativePath = '.local/share/virtualenvs';
2021-10-27 06:52:29 +00:00
}
2021-11-09 07:41:35 +00:00
const resolvedPath = path.join(os.homedir(), virtualEnvRelativePath);
2021-11-03 10:10:35 +00:00
core.debug(`global cache directory path is ${resolvedPath}`);
2021-10-27 06:52:29 +00:00
2021-11-03 10:10:35 +00:00
return [resolvedPath];
2021-10-27 06:52:29 +00:00
}
protected async computeKeys() {
const hash = await glob.hashFiles(this.patterns);
2021-11-09 07:41:35 +00:00
const primaryKey = `${this.CACHE_KEY_PREFIX}-${process.env['RUNNER_OS']}-python-${this.pythonVersion}-${this.packageManager}-${hash}`;
2021-10-27 06:52:29 +00:00
const restoreKey = undefined;
return {
primaryKey,
restoreKey
};
}
}
export default PipenvCache;