mirror of
https://code.forgejo.org/actions/setup-python
synced 2025-06-21 10:08:02 +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
44
src/cache-distributions/pipenv-cache.ts
Normal file
44
src/cache-distributions/pipenv-cache.ts
Normal file
|
@ -0,0 +1,44 @@
|
|||
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,
|
||||
protected patterns: string = '**/Pipfile.lock'
|
||||
) {
|
||||
super('pipenv', patterns);
|
||||
}
|
||||
|
||||
protected async getCacheGlobalDirectories() {
|
||||
let virtualEnvRelativePath;
|
||||
|
||||
// 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
|
||||
if (process.platform === 'win32') {
|
||||
virtualEnvRelativePath = '.virtualenvs';
|
||||
} else {
|
||||
virtualEnvRelativePath = '.local/share/virtualenvs';
|
||||
}
|
||||
const resolvedPath = path.join(os.homedir(), virtualEnvRelativePath);
|
||||
core.debug(`global cache directory path is ${resolvedPath}`);
|
||||
|
||||
return [resolvedPath];
|
||||
}
|
||||
|
||||
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
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export default PipenvCache;
|
Loading…
Add table
Add a link
Reference in a new issue