Skip to content

Commit

Permalink
Ensure escape on TOML and requirements is treated as cancel. (#20739)
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored Feb 27, 2023
1 parent 5d9bc1e commit 35be3c2
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ async function createEnvironment(options?: CreateEnvironmentOptions): Promise<Cr
throw ex;
}

if (version === undefined) {
traceError('Python version was not selected for creating conda environment.');
return MultiStepAction.Cancel;
}
return MultiStepAction.Continue;
},
undefined,
Expand Down
4 changes: 4 additions & 0 deletions src/client/pythonEnvironments/creation/provider/venvUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,8 @@ export async function pickPackagesToInstall(
});
}
packages.push({ installType: 'toml', source: tomlPath });
} else {
return MultiStepAction.Cancel;
}
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
Expand Down Expand Up @@ -192,6 +194,8 @@ export async function pickPackagesToInstall(
installList.forEach((i) => {
packages.push({ installType: 'requirements', installItem: i });
});
} else {
return MultiStepAction.Cancel;
}
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ suite('Conda Creation provider tests', () => {
});
pickPythonVersionStub.resolves(undefined);

assert.isUndefined(await condaProvider.createEnvironment());
await assert.isRejected(condaProvider.createEnvironment());
});

test('Create conda environment', async () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ suite('Venv Utils test', () => {
'[project]\nname = "spam"\nversion = "2020.0.0"\n[build-system]\nrequires = ["setuptools ~= 58.0", "cython ~= 0.29.0"]\n[project.optional-dependencies]\ntest = ["pytest"]\ndoc = ["sphinx", "furo"]',
);

showQuickPickWithBackStub.rejects(windowApis.MultiStepAction.Cancel);
showQuickPickWithBackStub.resolves(undefined);

await assert.isRejected(pickPackagesToInstall(workspace1));
assert.isTrue(
Expand Down Expand Up @@ -215,7 +215,7 @@ suite('Venv Utils test', () => {
return Promise.resolve([]);
});

showQuickPickWithBackStub.rejects(windowApis.MultiStepAction.Cancel);
showQuickPickWithBackStub.resolves(undefined);

await assert.isRejected(pickPackagesToInstall(workspace1));
assert.isTrue(
Expand Down

0 comments on commit 35be3c2

Please sign in to comment.