Readability improvement: Move CacheDistributor constructor params to readonly abstract fields of concrete cache implementations. Remove empty CacheDistributor constructor.

This commit is contained in:
Sam Pinkus 2025-01-08 16:09:52 +10:00
parent 3b3e184171
commit 3efe843c7b
4 changed files with 14 additions and 10 deletions

View File

@ -10,10 +10,8 @@ export enum State {
abstract class CacheDistributor {
protected CACHE_KEY_PREFIX = 'setup-python';
constructor(
protected packageManager: string,
protected cacheDependencyPath: string
) {}
protected abstract readonly packageManager: string;
protected abstract readonly cacheDependencyPath: string;
protected abstract getCacheGlobalDirectories(): Promise<string[]>;
protected abstract computeKeys(): Promise<{

View File

@ -12,12 +12,13 @@ import {CACHE_DEPENDENCY_BACKUP_PATH} from './constants';
class PipCache extends CacheDistributor {
private cacheDependencyBackupPath: string = CACHE_DEPENDENCY_BACKUP_PATH;
protected readonly packageManager = 'pip';
constructor(
private pythonVersion: string,
cacheDependencyPath = '**/requirements.txt'
protected readonly cacheDependencyPath = '**/requirements.txt'
) {
super('pip', cacheDependencyPath);
super();
}
protected async getCacheGlobalDirectories() {

View File

@ -6,11 +6,13 @@ import * as core from '@actions/core';
import CacheDistributor from './cache-distributor';
class PipenvCache extends CacheDistributor {
protected readonly packageManager = 'pipenv';
constructor(
private pythonVersion: string,
protected cacheDependencyPath: string = '**/Pipfile.lock'
protected readonly cacheDependencyPath: string = '**/Pipfile.lock'
) {
super('pipenv', cacheDependencyPath);
super();
}
protected async getCacheGlobalDirectories() {

View File

@ -8,12 +8,15 @@ import CacheDistributor from './cache-distributor';
import {logWarning} from '../utils';
class PoetryCache extends CacheDistributor {
protected readonly packageManager = 'poetry';
constructor(
private pythonVersion: string,
protected cacheDependencyPath: string = '**/poetry.lock',
protected readonly cacheDependencyPath: string = '**/poetry.lock',
protected poetryProjects: Set<string> = new Set<string>()
) {
super('poetry', cacheDependencyPath);
super();
}
protected async getCacheGlobalDirectories() {