Skip to content

Commit 6d74f8d

Browse files
authored
Ensure we don't show version selection when user selects useExisting (#22099)
Closes #22084
1 parent 2d3ce98 commit 6d74f8d

2 files changed

Lines changed: 44 additions & 12 deletions

File tree

src/client/pythonEnvironments/creation/provider/condaCreationProvider.ts

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -200,21 +200,30 @@ async function createEnvironment(options?: CreateEnvironmentOptions): Promise<Cr
200200
let version: string | undefined;
201201
const versionStep = new MultiStepNode(
202202
workspaceStep,
203-
async () => {
204-
try {
205-
version = await pickPythonVersion();
206-
} catch (ex) {
207-
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
208-
return ex;
203+
async (context) => {
204+
if (
205+
existingCondaAction === ExistingCondaAction.Recreate ||
206+
existingCondaAction === ExistingCondaAction.Create
207+
) {
208+
try {
209+
version = await pickPythonVersion();
210+
} catch (ex) {
211+
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
212+
return ex;
213+
}
214+
throw ex;
215+
}
216+
if (version === undefined) {
217+
traceError('Python version was not selected for creating conda environment.');
218+
return MultiStepAction.Cancel;
219+
}
220+
traceInfo(`Selected Python version ${version} for creating conda environment.`);
221+
} else if (existingCondaAction === ExistingCondaAction.UseExisting) {
222+
if (context === MultiStepAction.Back) {
223+
return MultiStepAction.Back;
209224
}
210-
throw ex;
211225
}
212226

213-
if (version === undefined) {
214-
traceError('Python version was not selected for creating conda environment.');
215-
return MultiStepAction.Cancel;
216-
}
217-
traceInfo(`Selected Python version ${version} for creating conda environment.`);
218227
return MultiStepAction.Continue;
219228
},
220229
undefined,

src/test/pythonEnvironments/creation/provider/condaCreationProvider.unit.test.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ suite('Conda Creation provider tests', () => {
3636
let withProgressStub: sinon.SinonStub;
3737
let showErrorMessageWithLogsStub: sinon.SinonStub;
3838
let pickExistingCondaActionStub: sinon.SinonStub;
39+
let getPrefixCondaEnvPathStub: sinon.SinonStub;
3940

4041
setup(() => {
4142
pickWorkspaceFolderStub = sinon.stub(wsSelect, 'pickWorkspaceFolder');
@@ -50,6 +51,8 @@ suite('Conda Creation provider tests', () => {
5051
pickExistingCondaActionStub = sinon.stub(condaUtils, 'pickExistingCondaAction');
5152
pickExistingCondaActionStub.resolves(condaUtils.ExistingCondaAction.Create);
5253

54+
getPrefixCondaEnvPathStub = sinon.stub(commonUtils, 'getPrefixCondaEnvPath');
55+
5356
progressMock = typemoq.Mock.ofType<CreateEnvironmentProgress>();
5457
condaProvider = condaCreationProvider();
5558
});
@@ -254,4 +257,24 @@ suite('Conda Creation provider tests', () => {
254257
assert.isTrue(showErrorMessageWithLogsStub.calledOnce);
255258
assert.isTrue(pickExistingCondaActionStub.calledOnce);
256259
});
260+
261+
test('Use existing conda environment', async () => {
262+
getCondaBaseEnvStub.resolves('/usr/bin/conda');
263+
const workspace1 = {
264+
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
265+
name: 'workspace1',
266+
index: 0,
267+
};
268+
pickWorkspaceFolderStub.resolves(workspace1);
269+
pickExistingCondaActionStub.resolves(condaUtils.ExistingCondaAction.UseExisting);
270+
getPrefixCondaEnvPathStub.returns('existing_environment');
271+
272+
const result = await condaProvider.createEnvironment();
273+
assert.isTrue(showErrorMessageWithLogsStub.notCalled);
274+
assert.isTrue(pickPythonVersionStub.notCalled);
275+
assert.isTrue(execObservableStub.notCalled);
276+
assert.isTrue(withProgressStub.notCalled);
277+
278+
assert.deepStrictEqual(result, { path: 'existing_environment', workspaceFolder: workspace1 });
279+
});
257280
});

0 commit comments

Comments
 (0)