Skip to content

Commit

Permalink
Fixes to conda activation (#6261)
Browse files Browse the repository at this point in the history
  • Loading branch information
DonJayamanne authored Jun 20, 2019
1 parent f7321ec commit 6b1b8a3
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { ITerminalActivationCommandProvider, TerminalShellType } from '../types'
// Version number of conda that requires we call activate with 'conda activate' instead of just 'activate'
const CondaRequiredMajor = 4;
const CondaRequiredMinor = 4;
const CondaRequiredMinorForPowerShell = 6;

/**
* Support conda env activation (in the terminal).
Expand All @@ -25,7 +26,7 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
@inject(ICondaService) private readonly condaService: ICondaService,
@inject(IPlatformService) private platform: IPlatformService,
@inject(IConfigurationService) private configService: IConfigurationService
) {}
) { }

/**
* Is the given shell supported for activating a conda env?
Expand Down Expand Up @@ -57,13 +58,20 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
// New version, call activate from the same path as our python path, then call it again to activate our environment.
// -- note that the 'default' conda location won't allow activate to work for the environment sometimes.
const versionInfo = await this.condaService.getCondaVersion();
if (versionInfo && (versionInfo.major > CondaRequiredMajor || (versionInfo.major === CondaRequiredMajor && versionInfo.minor >= CondaRequiredMinor))) {
// New version.
const interpreterPath = await this.condaService.getCondaFileFromInterpreter(pythonPath, envInfo.name);
if (interpreterPath) {
const activatePath = path.join(path.dirname(interpreterPath), 'activate').fileToCommandArgument();
const firstActivate = this.platform.isWindows ? activatePath : `source ${activatePath}`;
return [firstActivate, `conda activate ${envInfo.name.toCommandArgument()}`];
if (versionInfo && versionInfo.major >= CondaRequiredMajor) {
// Conda added support for powershell in 4.6.
if (versionInfo.minor >= CondaRequiredMinorForPowerShell &&
(targetShell === TerminalShellType.powershell || targetShell === TerminalShellType.powershellCore)) {
return this.getPowershellCommands(envInfo.name);
}
if (versionInfo.minor >= CondaRequiredMinor) {
// New version.
const interpreterPath = await this.condaService.getCondaFileFromInterpreter(pythonPath, envInfo.name);
if (interpreterPath) {
const activatePath = path.join(path.dirname(interpreterPath), 'activate').fileToCommandArgument();
const firstActivate = this.platform.isWindows ? activatePath : `source ${activatePath}`;
return [firstActivate, `conda activate ${envInfo.name.toCommandArgument()}`];
}
}
}

Expand Down

0 comments on commit 6b1b8a3

Please sign in to comment.