Skip to content

Conda activation fails when there is a space in the env name #4717

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 12, 2019
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
1 change: 1 addition & 0 deletions news/2 Fixes/4243.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Conda activation fails when there is a space in the env name
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
`source ${activatePath}`;
return [
firstActivate,
`conda activate ${envInfo.name}`
`conda activate ${envInfo.name.toCommandArgument()}`
];
}
}
Expand Down
53 changes: 53 additions & 0 deletions src/test/common/terminals/activation.conda.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,59 @@ suite('Terminal Environment Activation conda', () => {
expect(activationCommands).to.deep.equal(expected, 'Incorrect Activation command');
});

const interpreterPath = path.join('path', 'to', 'interpreter');
const environmentName = 'Env';
const environmentNameHasSpaces = 'Env with spaces';
const testsForActivationUsingInterpreterPath =
[
{
testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with no spaces in env name',
envName: environmentName,
expectedResult: ['path/to/activate', 'conda activate Env'],
isWindows: true
},
{
testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with no spaces in env name',
envName: environmentName,
expectedResult: ['source path/to/activate', 'conda activate Env'],
isWindows: false
},
{
testName: 'Activation provides correct activation commands (windows) after 4.4.0 given interpreter path is provided, with spaces in env name',
envName: environmentNameHasSpaces,
expectedResult: ['path/to/activate', 'conda activate \"Env with spaces\"'],
isWindows: true
},
{
testName: 'Activation provides correct activation commands (non-windows) after 4.4.0 given interpreter path is provided, with spaces in env name',
envName: environmentNameHasSpaces,
expectedResult: ['source path/to/activate', 'conda activate \"Env with spaces\"'],
isWindows: false
}
];

testsForActivationUsingInterpreterPath.forEach((testParams) => {
test(testParams.testName, async () => {
const pythonPath = 'python3';
platformService.setup(p => p.isWindows).returns(() => testParams.isWindows);
condaService.reset();
condaService.setup(c => c.getCondaEnvironment(TypeMoq.It.isAny()))
.returns(() => Promise.resolve({
name: testParams.envName,
path: path.dirname(pythonPath)
}));
condaService.setup(c => c.getCondaVersion())
.returns(() => Promise.resolve(parse('4.4.0', true)!));
condaService.setup(c => c.getCondaFileFromInterpreter(TypeMoq.It.isAny(), TypeMoq.It.isAny()))
.returns(() => Promise.resolve(interpreterPath));

const provider = new CondaActivationCommandProvider(condaService.object, platformService.object, configService.object);
const activationCommands = await provider.getActivationCommands(undefined, TerminalShellType.bash);

expect(activationCommands).to.deep.equal(testParams.expectedResult, 'Incorrect Activation command');
});
});

async function expectNoCondaActivationCommandForPowershell(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string, shellType: TerminalShellType, hasSpaceInEnvironmentName = false) {
terminalSettings.setup(t => t.activateEnvironment).returns(() => true);
platformService.setup(p => p.isLinux).returns(() => isLinux);
Expand Down