Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -200,21 +200,30 @@ async function createEnvironment(options?: CreateEnvironmentOptions): Promise<Cr
let version: string | undefined;
const versionStep = new MultiStepNode(
workspaceStep,
async () => {
try {
version = await pickPythonVersion();
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
return ex;
async (context) => {
if (
existingCondaAction === ExistingCondaAction.Recreate ||
existingCondaAction === ExistingCondaAction.Create
) {
try {
version = await pickPythonVersion();
} catch (ex) {
if (ex === MultiStepAction.Back || ex === MultiStepAction.Cancel) {
return ex;
}
throw ex;
}
if (version === undefined) {
traceError('Python version was not selected for creating conda environment.');
return MultiStepAction.Cancel;
}
traceInfo(`Selected Python version ${version} for creating conda environment.`);
} else if (existingCondaAction === ExistingCondaAction.UseExisting) {
if (context === MultiStepAction.Back) {
return MultiStepAction.Back;
}
throw ex;
}

if (version === undefined) {
traceError('Python version was not selected for creating conda environment.');
return MultiStepAction.Cancel;
}
traceInfo(`Selected Python version ${version} for creating conda environment.`);
return MultiStepAction.Continue;
},
undefined,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ suite('Conda Creation provider tests', () => {
let withProgressStub: sinon.SinonStub;
let showErrorMessageWithLogsStub: sinon.SinonStub;
let pickExistingCondaActionStub: sinon.SinonStub;
let getPrefixCondaEnvPathStub: sinon.SinonStub;

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

getPrefixCondaEnvPathStub = sinon.stub(commonUtils, 'getPrefixCondaEnvPath');

progressMock = typemoq.Mock.ofType<CreateEnvironmentProgress>();
condaProvider = condaCreationProvider();
});
Expand Down Expand Up @@ -254,4 +257,24 @@ suite('Conda Creation provider tests', () => {
assert.isTrue(showErrorMessageWithLogsStub.calledOnce);
assert.isTrue(pickExistingCondaActionStub.calledOnce);
});

test('Use existing conda environment', async () => {
getCondaBaseEnvStub.resolves('/usr/bin/conda');
const workspace1 = {
uri: Uri.file(path.join(EXTENSION_ROOT_DIR_FOR_TESTS, 'src', 'testMultiRootWkspc', 'workspace1')),
name: 'workspace1',
index: 0,
};
pickWorkspaceFolderStub.resolves(workspace1);
pickExistingCondaActionStub.resolves(condaUtils.ExistingCondaAction.UseExisting);
getPrefixCondaEnvPathStub.returns('existing_environment');

const result = await condaProvider.createEnvironment();
assert.isTrue(showErrorMessageWithLogsStub.notCalled);
assert.isTrue(pickPythonVersionStub.notCalled);
assert.isTrue(execObservableStub.notCalled);
assert.isTrue(withProgressStub.notCalled);

assert.deepStrictEqual(result, { path: 'existing_environment', workspaceFolder: workspace1 });
});
});