Code improvemnt: Rm CacheDistributor.cacheDependencyPath field and pass back from computeKeys instead, simplifying CacheDistributor.restoreCache error check. Rm now uneeded constant.ts file.

This commit is contained in:
Sam Pinkus 2025-01-08 16:37:25 +10:00
parent 0024ce0d14
commit d99639b3c5
5 changed files with 16 additions and 18 deletions

View file

@ -8,10 +8,9 @@ import os from 'os';
import CacheDistributor from './cache-distributor';
import {getLinuxInfo, IS_LINUX, IS_WINDOWS} from '../utils';
import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
class PipCache extends CacheDistributor {
private cacheDependencyBackupPath: string = CACHE_DEPENDENCY_BACKUP_PATH;
private cacheDependencyBackupPath = '**/pyproject.toml';
protected readonly packageManager = 'pip';
constructor(
@ -60,9 +59,12 @@ class PipCache extends CacheDistributor {
}
protected async computeKeys() {
const hash =
(await glob.hashFiles(this.cacheDependencyPath)) ||
(await glob.hashFiles(this.cacheDependencyBackupPath));
let cacheDependencyPath = this.cacheDependencyPath;
let hash = await glob.hashFiles(this.cacheDependencyPath);
if(!hash) {
hash = await glob.hashFiles(this.cacheDependencyBackupPath);
cacheDependencyPath = this.cacheDependencyBackupPath;
}
let primaryKey = '';
let restoreKey = '';
@ -77,7 +79,8 @@ class PipCache extends CacheDistributor {
return {
primaryKey,
restoreKey: [restoreKey]
restoreKey: [restoreKey],
cacheDependencyPath,
};
}
}