Skip to content
Closed
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/3810.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sends correct conda activation command in windows gitbash
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -103,6 +107,16 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
];
}

public async getBashCommands(
envName: string
): Promise<string[] | undefined> {

const activate = await this.getWindowsActivateCommand();
return [
`source ${activate} ${envName.toCommandArgument()}`
];
}

public async getPowershellCommands(
envName: string,
targetShell: TerminalShellType
Expand Down
39 changes: 23 additions & 16 deletions src/test/common/terminals/activation.conda.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand All @@ -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>(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 () => {
Expand Down