Skip to content

Commit b24407b

Browse files
Kartik RajDonJayamanne
Kartik Raj
authored andcommitted
Conda activation fails when there is a space in the env name (#4717)
For #4273
1 parent e28d148 commit b24407b

File tree

3 files changed

+55
-1
lines changed

3 files changed

+55
-1
lines changed

news/2 Fixes/4243.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Conda activation fails when there is a space in the env name

src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
6767
`source ${activatePath}`;
6868
return [
6969
firstActivate,
70-
`conda activate ${envInfo.name}`
70+
`conda activate ${envInfo.name.toCommandArgument()}`
7171
];
7272
}
7373
}

src/test/common/terminals/activation.conda.unit.test.ts

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,59 @@ suite('Terminal Environment Activation conda', () => {
170170
expect(activationCommands).to.deep.equal(expected, 'Incorrect Activation command');
171171
});
172172

173+
const interpreterPath = path.join('path', 'to', 'interpreter');
174+
const environmentName = 'Env';
175+
const environmentNameHasSpaces = 'Env with spaces';
176+
const testsForActivationUsingInterpreterPath =
177+
[
178+
{
179+
testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with no spaces in env name',
180+
envName: environmentName,
181+
expectedResult: ['path/to/activate', 'conda activate Env'],
182+
isWindows: true
183+
},
184+
{
185+
testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with no spaces in env name',
186+
envName: environmentName,
187+
expectedResult: ['source path/to/activate', 'conda activate Env'],
188+
isWindows: false
189+
},
190+
{
191+
testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with spaces in env name',
192+
envName: environmentNameHasSpaces,
193+
expectedResult: ['path/to/activate', 'conda activate \"Env with spaces\"'],
194+
isWindows: true
195+
},
196+
{
197+
testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with spaces in env name',
198+
envName: environmentNameHasSpaces,
199+
expectedResult: ['source path/to/activate', 'conda activate \"Env with spaces\"'],
200+
isWindows: false
201+
}
202+
];
203+
204+
testsForActivationUsingInterpreterPath.forEach((testParams) => {
205+
test(testParams.testName, async () => {
206+
const pythonPath = 'python3';
207+
platformService.setup(p => p.isWindows).returns(() => testParams.isWindows);
208+
condaService.reset();
209+
condaService.setup(c => c.getCondaEnvironment(TypeMoq.It.isAny()))
210+
.returns(() => Promise.resolve({
211+
name: testParams.envName,
212+
path: path.dirname(pythonPath)
213+
}));
214+
condaService.setup(c => c.getCondaVersion())
215+
.returns(() => Promise.resolve(parse('4.4.0', true)!));
216+
condaService.setup(c => c.getCondaFileFromInterpreter(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
217+
.returns(() => Promise.resolve(interpreterPath));
218+
219+
const provider = new CondaActivationCommandProvider(condaService.object, platformService.object, configService.object);
220+
const activationCommands = await provider.getActivationCommands(undefined, TerminalShellType.bash);
221+
222+
expect(activationCommands).to.deep.equal(testParams.expectedResult, 'Incorrect Activation command');
223+
});
224+
});
225+
173226
async function expectNoCondaActivationCommandForPowershell(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string, shellType: TerminalShellType, hasSpaceInEnvironmentName = false) {
174227
terminalSettings.setup(t => t.activateEnvironment).returns(() => true);
175228
platformService.setup(p => p.isLinux).returns(() => isLinux);

0 commit comments

Comments
 (0)