From a2bc33042cb72069af2f1dd8fead59d548bb260d Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Thu, 27 Dec 2018 15:22:49 -0500 Subject: [PATCH 1/3] Fix conda activation command for bash in windows --- .../condaActivationProvider.ts | 14 +++++++ .../terminals/activation.conda.unit.test.ts | 39 +++++++++++-------- 2 files changed, 37 insertions(+), 16 deletions(-) diff --git a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts index a2087507f72c..eaf9da8c62b5 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 () => { From e678fc6cd68f9cfbbd2fde726c04f5028c3cee1a Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Thu, 27 Dec 2018 15:32:15 -0500 Subject: [PATCH 2/3] Fix indent --- .../condaActivationProvider.ts | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts index eaf9da8c62b5..08e2d9ff41da 100644 --- a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts +++ b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts @@ -49,9 +49,9 @@ 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); + 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? From acc9b0dd66978a2cf37919194e637cd900fd39c3 Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Mon, 7 Jan 2019 18:49:11 -0500 Subject: [PATCH 3/3] Add news entry --- news/2 Fixes/3810.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 news/2 Fixes/3810.md 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