Skip to content

Commit a2bc330

Browse files
committed
Fix conda activation command for bash in windows
1 parent 4f19099 commit a2bc330

File tree

2 files changed

+37
-16
lines changed

2 files changed

+37
-16
lines changed

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,10 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
4949
case TerminalShellType.powershellCore:
5050
return this.getPowershellCommands(envInfo.name, targetShell);
5151

52+
case TerminalShellType.bash:
53+
case TerminalShellType.gitbash:
54+
return this.getBashCommands(envInfo.name);
55+
5256
// tslint:disable-next-line:no-suspicious-comment
5357
// TODO: Do we really special-case fish on Windows?
5458
case TerminalShellType.fish:
@@ -103,6 +107,16 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
103107
];
104108
}
105109

110+
public async getBashCommands(
111+
envName: string
112+
): Promise<string[] | undefined> {
113+
114+
const activate = await this.getWindowsActivateCommand();
115+
return [
116+
`source ${activate} ${envName.toCommandArgument()}`
117+
];
118+
}
119+
106120
public async getPowershellCommands(
107121
envName: string,
108122
targetShell: TerminalShellType

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

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ suite('Terminal Environment Activation conda', () => {
171171
expectedActivationCommamnd = [`conda activate ${envName.toCommandArgument()}`];
172172
break;
173173
}
174+
case TerminalShellType.bash:
175+
case TerminalShellType.gitbash: {
176+
expectedActivationCommamnd = [`source activate ${envName.toCommandArgument()}`];
177+
break;
178+
}
174179
default: {
175180
expectedActivationCommamnd = isWindows ? [`activate ${envName.toCommandArgument()}`] : [`source activate ${envName.toCommandArgument()}`];
176181
break;
@@ -214,7 +219,7 @@ suite('Terminal Environment Activation conda', () => {
214219
await expectNoCondaActivationCommandForPowershell(false, true, false, pythonPath, shellType.value, true);
215220
});
216221
});
217-
async function expectCondaActivationCommand(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string) {
222+
async function expectCondaActivationCommand(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string, shellType: TerminalShellType) {
218223
terminalSettings.setup(t => t.activateEnvironment).returns(() => true);
219224
platformService.setup(p => p.isLinux).returns(() => isLinux);
220225
platformService.setup(p => p.isWindows).returns(() => isWindows);
@@ -223,27 +228,29 @@ suite('Terminal Environment Activation conda', () => {
223228
pythonSettings.setup(s => s.pythonPath).returns(() => pythonPath);
224229
condaService.setup(c => c.getCondaEnvironment(TypeMoq.It.isAny())).returns(() => Promise.resolve({ name: 'EnvA', path: path.dirname(pythonPath) }));
225230

226-
const expectedActivationCommand = isWindows ? ['activate EnvA'] : ['source activate EnvA'];
231+
const expectedActivationCommand = isWindows && !(TerminalShellType.bash || TerminalShellType.gitbash) ? ['activate EnvA'] : ['source activate EnvA'];
227232
const activationCommands = await terminalHelper.getEnvironmentActivationCommands(TerminalShellType.bash, undefined);
228233
expect(activationCommands).to.deep.equal(expectedActivationCommand, 'Incorrect Activation command');
229234
}
230235

231-
test('If environment is a conda environment, ensure conda activation command is sent (windows)', async () => {
232-
const pythonPath = path.join('c', 'users', 'xyz', '.conda', 'envs', 'enva', 'python.exe');
233-
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), 'conda-meta')))).returns(() => Promise.resolve(true));
234-
await expectCondaActivationCommand(true, false, false, pythonPath);
235-
});
236+
getNamesAndValues<TerminalShellType>(TerminalShellType).forEach(shellType => {
237+
test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (windows)`, async () => {
238+
const pythonPath = path.join('c', 'users', 'xyz', '.conda', 'envs', 'enva', 'python.exe');
239+
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), 'conda-meta')))).returns(() => Promise.resolve(true));
240+
await expectCondaActivationCommand(true, false, false, pythonPath, shellType.value);
241+
});
236242

237-
test('If environment is a conda environment, ensure conda activation command is sent (linux)', async () => {
238-
const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python');
239-
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true));
240-
await expectCondaActivationCommand(false, false, true, pythonPath);
241-
});
243+
test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (linux)`, async () => {
244+
const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python');
245+
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true));
246+
await expectCondaActivationCommand(false, false, true, pythonPath, shellType.value);
247+
});
242248

243-
test('If environment is a conda environment, ensure conda activation command is sent (osx)', async () => {
244-
const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python');
245-
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true));
246-
await expectCondaActivationCommand(false, true, false, pythonPath);
249+
test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (osx)`, async () => {
250+
const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python');
251+
fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true));
252+
await expectCondaActivationCommand(false, true, false, pythonPath, shellType.value);
253+
});
247254
});
248255

249256
test('Get activation script command if environment is not a conda environment', async () => {

0 commit comments

Comments
 (0)