diff --git a/news/2 Fixes/3810.md b/news/2 Fixes/3810.md new file mode 100644 index 000000000000..29671b35a5ff --- /dev/null +++ b/news/2 Fixes/3810.md @@ -0,0 +1 @@ +Sends correct conda activation command in windows gitbash diff --git a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts index a2087507f72c..08e2d9ff41da 100644 --- a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts +++ b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts @@ -49,6 +49,10 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman case TerminalShellType.powershellCore: return this.getPowershellCommands(envInfo.name, targetShell); + case TerminalShellType.bash: + case TerminalShellType.gitbash: + return this.getBashCommands(envInfo.name); + // tslint:disable-next-line:no-suspicious-comment // TODO: Do we really special-case fish on Windows? case TerminalShellType.fish: @@ -103,6 +107,16 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman ]; } + public async getBashCommands( + envName: string + ): Promise { + + const activate = await this.getWindowsActivateCommand(); + return [ + `source ${activate} ${envName.toCommandArgument()}` + ]; + } + public async getPowershellCommands( envName: string, targetShell: TerminalShellType diff --git a/src/test/common/terminals/activation.conda.unit.test.ts b/src/test/common/terminals/activation.conda.unit.test.ts index 3a906d1b79c2..fa5c08b81311 100644 --- a/src/test/common/terminals/activation.conda.unit.test.ts +++ b/src/test/common/terminals/activation.conda.unit.test.ts @@ -171,6 +171,11 @@ suite('Terminal Environment Activation conda', () => { expectedActivationCommamnd = [`conda activate ${envName.toCommandArgument()}`]; break; } + case TerminalShellType.bash: + case TerminalShellType.gitbash: { + expectedActivationCommamnd = [`source activate ${envName.toCommandArgument()}`]; + break; + } default: { expectedActivationCommamnd = isWindows ? [`activate ${envName.toCommandArgument()}`] : [`source activate ${envName.toCommandArgument()}`]; break; @@ -214,7 +219,7 @@ suite('Terminal Environment Activation conda', () => { await expectNoCondaActivationCommandForPowershell(false, true, false, pythonPath, shellType.value, true); }); }); - async function expectCondaActivationCommand(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string) { + async function expectCondaActivationCommand(isWindows: boolean, isOsx: boolean, isLinux: boolean, pythonPath: string, shellType: TerminalShellType) { terminalSettings.setup(t => t.activateEnvironment).returns(() => true); platformService.setup(p => p.isLinux).returns(() => isLinux); platformService.setup(p => p.isWindows).returns(() => isWindows); @@ -223,27 +228,29 @@ suite('Terminal Environment Activation conda', () => { pythonSettings.setup(s => s.pythonPath).returns(() => pythonPath); condaService.setup(c => c.getCondaEnvironment(TypeMoq.It.isAny())).returns(() => Promise.resolve({ name: 'EnvA', path: path.dirname(pythonPath) })); - const expectedActivationCommand = isWindows ? ['activate EnvA'] : ['source activate EnvA']; + const expectedActivationCommand = isWindows && !(TerminalShellType.bash || TerminalShellType.gitbash) ? ['activate EnvA'] : ['source activate EnvA']; const activationCommands = await terminalHelper.getEnvironmentActivationCommands(TerminalShellType.bash, undefined); expect(activationCommands).to.deep.equal(expectedActivationCommand, 'Incorrect Activation command'); } - test('If environment is a conda environment, ensure conda activation command is sent (windows)', async () => { - const pythonPath = path.join('c', 'users', 'xyz', '.conda', 'envs', 'enva', 'python.exe'); - fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), 'conda-meta')))).returns(() => Promise.resolve(true)); - await expectCondaActivationCommand(true, false, false, pythonPath); - }); + getNamesAndValues(TerminalShellType).forEach(shellType => { + test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (windows)`, async () => { + const pythonPath = path.join('c', 'users', 'xyz', '.conda', 'envs', 'enva', 'python.exe'); + fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), 'conda-meta')))).returns(() => Promise.resolve(true)); + await expectCondaActivationCommand(true, false, false, pythonPath, shellType.value); + }); - test('If environment is a conda environment, ensure conda activation command is sent (linux)', async () => { - const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python'); - fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true)); - await expectCondaActivationCommand(false, false, true, pythonPath); - }); + test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (linux)`, async () => { + const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python'); + fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true)); + await expectCondaActivationCommand(false, false, true, pythonPath, shellType.value); + }); - test('If environment is a conda environment, ensure conda activation command is sent (osx)', async () => { - const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python'); - fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true)); - await expectCondaActivationCommand(false, true, false, pythonPath); + test(`If environment is a conda environment, ensure conda activation command is sent for shell ${shellType.name} (osx)`, async () => { + const pythonPath = path.join('users', 'xyz', '.conda', 'envs', 'enva', 'bin', 'python'); + fileSystem.setup(f => f.directoryExists(TypeMoq.It.isValue(path.join(path.dirname(pythonPath), '..', 'conda-meta')))).returns(() => Promise.resolve(true)); + await expectCondaActivationCommand(false, true, false, pythonPath, shellType.value); + }); }); test('Get activation script command if environment is not a conda environment', async () => {