From 84e3309849b9d936eb85602232f05a3116c76bc3 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 23 Feb 2023 13:21:37 -0800 Subject: [PATCH 1/2] Ensure escape on TOML and requirements is treated as cancel. --- src/client/pythonEnvironments/creation/provider/venvUtils.ts | 4 ++++ .../creation/provider/venvUtils.unit.test.ts | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/client/pythonEnvironments/creation/provider/venvUtils.ts b/src/client/pythonEnvironments/creation/provider/venvUtils.ts index aa2ec7efca9e..76012e7f7aef 100644 --- a/src/client/pythonEnvironments/creation/provider/venvUtils.ts +++ b/src/client/pythonEnvironments/creation/provider/venvUtils.ts @@ -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) { @@ -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) { diff --git a/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts b/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts index a0d030853717..360bb43fad4b 100644 --- a/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts +++ b/src/test/pythonEnvironments/creation/provider/venvUtils.unit.test.ts @@ -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( @@ -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( From 1eb3033695a22e12463a92078984696e9519a76b Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Fri, 24 Feb 2023 15:29:17 -0800 Subject: [PATCH 2/2] Ensure cancellation is supported for conda env creation. --- .../creation/provider/condaCreationProvider.ts | 4 ++++ .../creation/provider/condaCreationProvider.unit.test.ts | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/client/pythonEnvironments/creation/provider/condaCreationProvider.ts b/src/client/pythonEnvironments/creation/provider/condaCreationProvider.ts index 28046cbc73ad..5bf032f9f65f 100644 --- a/src/client/pythonEnvironments/creation/provider/condaCreationProvider.ts +++ b/src/client/pythonEnvironments/creation/provider/condaCreationProvider.ts @@ -192,6 +192,10 @@ async function createEnvironment(options?: CreateEnvironmentOptions): Promise { }); pickPythonVersionStub.resolves(undefined); - assert.isUndefined(await condaProvider.createEnvironment()); + await assert.isRejected(condaProvider.createEnvironment()); }); test('Create conda environment', async () => {