mirror of
https://gitea.com/actions/setup-python.git
synced 2024-11-23 02:29:35 +01:00
Add fix for Windows caching of pip (#332)
This commit is contained in:
parent
dc9de69ff3
commit
7f80679172
3 changed files with 46 additions and 6 deletions
|
@ -96,7 +96,8 @@ describe('restore-cache', () => {
|
||||||
expect(infoSpy).toHaveBeenCalledWith(
|
expect(infoSpy).toHaveBeenCalledWith(
|
||||||
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
`Cache restored from key: setup-python-${process.env['RUNNER_OS']}-python-${pythonVersion}-${packageManager}-${fileHash}`
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
30000
|
||||||
);
|
);
|
||||||
|
|
||||||
it.each([
|
it.each([
|
||||||
|
|
23
dist/setup/index.js
vendored
23
dist/setup/index.js
vendored
|
@ -34463,9 +34463,12 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const glob = __importStar(__webpack_require__(281));
|
const glob = __importStar(__webpack_require__(281));
|
||||||
const core = __importStar(__webpack_require__(470));
|
const core = __importStar(__webpack_require__(470));
|
||||||
const exec = __importStar(__webpack_require__(986));
|
const exec = __importStar(__webpack_require__(986));
|
||||||
|
const child_process = __importStar(__webpack_require__(129));
|
||||||
|
const util_1 = __importDefault(__webpack_require__(669));
|
||||||
const path = __importStar(__webpack_require__(622));
|
const path = __importStar(__webpack_require__(622));
|
||||||
const os_1 = __importDefault(__webpack_require__(87));
|
const os_1 = __importDefault(__webpack_require__(87));
|
||||||
const cache_distributor_1 = __importDefault(__webpack_require__(435));
|
const cache_distributor_1 = __importDefault(__webpack_require__(435));
|
||||||
|
const utils_1 = __webpack_require__(163);
|
||||||
class PipCache extends cache_distributor_1.default {
|
class PipCache extends cache_distributor_1.default {
|
||||||
constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') {
|
constructor(pythonVersion, cacheDependencyPath = '**/requirements.txt') {
|
||||||
super('pip', cacheDependencyPath);
|
super('pip', cacheDependencyPath);
|
||||||
|
@ -34473,7 +34476,25 @@ class PipCache extends cache_distributor_1.default {
|
||||||
}
|
}
|
||||||
getCacheGlobalDirectories() {
|
getCacheGlobalDirectories() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
const { stdout, stderr, exitCode } = yield exec.getExecOutput('pip cache dir');
|
let exitCode = 1;
|
||||||
|
let stdout = '';
|
||||||
|
let stderr = '';
|
||||||
|
// Add temporary fix for Windows
|
||||||
|
// On windows it is necessary to execute through an exec
|
||||||
|
// because the getExecOutput gives a non zero code or writes to stderr for pip 22.0.2,
|
||||||
|
// or spawn must be started with the shell option enabled for getExecOutput
|
||||||
|
// Related issue: https://github.com/actions/setup-python/issues/328
|
||||||
|
if (utils_1.IS_WINDOWS) {
|
||||||
|
const execPromisify = util_1.default.promisify(child_process.exec);
|
||||||
|
({ stdout: stdout, stderr: stderr } = yield execPromisify('pip cache dir'));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
({
|
||||||
|
stdout: stdout,
|
||||||
|
stderr: stderr,
|
||||||
|
exitCode: exitCode
|
||||||
|
} = yield exec.getExecOutput('pip cache dir'));
|
||||||
|
}
|
||||||
if (exitCode && stderr) {
|
if (exitCode && stderr) {
|
||||||
throw new Error(`Could not get cache folder path for pip package manager`);
|
throw new Error(`Could not get cache folder path for pip package manager`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
import * as glob from '@actions/glob';
|
import * as glob from '@actions/glob';
|
||||||
import * as core from '@actions/core';
|
import * as core from '@actions/core';
|
||||||
import * as exec from '@actions/exec';
|
import * as exec from '@actions/exec';
|
||||||
|
import * as child_process from 'child_process';
|
||||||
|
import utils from 'util';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import os from 'os';
|
import os from 'os';
|
||||||
|
|
||||||
import CacheDistributor from './cache-distributor';
|
import CacheDistributor from './cache-distributor';
|
||||||
|
import {IS_WINDOWS} from '../utils';
|
||||||
|
|
||||||
class PipCache extends CacheDistributor {
|
class PipCache extends CacheDistributor {
|
||||||
constructor(
|
constructor(
|
||||||
|
@ -16,9 +18,25 @@ class PipCache extends CacheDistributor {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected async getCacheGlobalDirectories() {
|
protected async getCacheGlobalDirectories() {
|
||||||
const {stdout, stderr, exitCode} = await exec.getExecOutput(
|
let exitCode = 1;
|
||||||
'pip cache dir'
|
let stdout = '';
|
||||||
);
|
let stderr = '';
|
||||||
|
|
||||||
|
// Add temporary fix for Windows
|
||||||
|
// On windows it is necessary to execute through an exec
|
||||||
|
// because the getExecOutput gives a non zero code or writes to stderr for pip 22.0.2,
|
||||||
|
// or spawn must be started with the shell option enabled for getExecOutput
|
||||||
|
// Related issue: https://github.com/actions/setup-python/issues/328
|
||||||
|
if (IS_WINDOWS) {
|
||||||
|
const execPromisify = utils.promisify(child_process.exec);
|
||||||
|
({stdout: stdout, stderr: stderr} = await execPromisify('pip cache dir'));
|
||||||
|
} else {
|
||||||
|
({
|
||||||
|
stdout: stdout,
|
||||||
|
stderr: stderr,
|
||||||
|
exitCode: exitCode
|
||||||
|
} = await exec.getExecOutput('pip cache dir'));
|
||||||
|
}
|
||||||
|
|
||||||
if (exitCode && stderr) {
|
if (exitCode && stderr) {
|
||||||
throw new Error(
|
throw new Error(
|
||||||
|
|
Loading…
Reference in a new issue