Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pip cache error handling on Windows. #1040

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions dist/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -98893,24 +98893,25 @@ class PipCache extends cache_distributor_1.default {
}
getCacheGlobalDirectories() {
return __awaiter(this, void 0, void 0, function* () {
let exitCode = 1;
let exitCode = 0;
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,
// 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'));
try {
({ stdout, stderr } = yield execPromisify('pip cache dir'));
}
catch (err) {
exitCode = 1;
}
}
else {
({
stdout: stdout,
stderr: stderr,
exitCode: exitCode
} = yield exec.getExecOutput('pip cache dir'));
({ stdout, stderr, exitCode } = yield exec.getExecOutput('pip cache dir'));
}
if (exitCode && stderr) {
throw new Error(`Could not get cache folder path for pip package manager`);
Expand Down
18 changes: 9 additions & 9 deletions src/cache-distributions/pip-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,24 @@ class PipCache extends CacheDistributor {
}

protected async getCacheGlobalDirectories() {
let exitCode = 1;
let exitCode = 0;
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,
// 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'));
try {
({stdout, stderr} = await execPromisify('pip cache dir'));
} catch (err) {
exitCode = 1;
}
} else {
({
stdout: stdout,
stderr: stderr,
exitCode: exitCode
} = await exec.getExecOutput('pip cache dir'));
({stdout, stderr, exitCode} = await exec.getExecOutput('pip cache dir'));
}

if (exitCode && stderr) {
Expand Down