renovate/lib/manager/pip_setup/util.ts
Rhys Arkins 0e91fda451 feat: centralized cache directory (#10115)
Ignore environment variables and instead use static cache directory for third party tools.

Closes #10094

BREAKING CHANGE: Renovate will now override any package manager cache locations configured in env variables.
# Conflicts:
#	lib/manager/gomod/__snapshots__/artifacts.spec.ts.snap
#	lib/manager/gomod/artifacts.ts
2021-08-17 07:57:45 +02:00

27 lines
861 B
TypeScript

import { dirname } from 'path';
import { join } from 'upath';
import dataFiles from '../../data-files.generated';
import { ensureCacheDir, outputFile, readLocalFile } from '../../util/fs';
import type { PythonSetup } from './types';
// need to match filename in `data/extract.py`
const REPORT = 'renovate-pip_setup-report.json';
const EXTRACT = 'renovate-pip_setup-extract.py';
let extractPy: string | undefined;
export async function getExtractFile(): Promise<string> {
if (extractPy) {
return extractPy;
}
extractPy = join(await ensureCacheDir('pip_setup'), EXTRACT);
await outputFile(extractPy, dataFiles.get('data/extract.py'));
return extractPy;
}
export async function parseReport(packageFile: string): Promise<PythonSetup> {
const data = await readLocalFile(join(dirname(packageFile), REPORT), 'utf8');
return JSON.parse(data);
}