Skip to content
Closed
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
48 changes: 47 additions & 1 deletion src/managers/conda/condaUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ function isPrefixOf(roots: string[], e: string): boolean {
return false;
}

let condaActivateScriptCache: string | undefined = undefined;
async function getNamedCondaPythonInfo(
name: string,
prefix: string,
Expand All @@ -291,7 +292,52 @@ async function getNamedCondaPythonInfo(
const shellActivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
const shellDeactivation: Map<string, PythonCommandRunConfiguration[]> = new Map();

if (conda.includes('/') || conda.includes('\\')) {
let activateScriptPath = undefined;

// check if bin/activate script exists
const condaFolder = path.dirname(path.dirname(conda));

// this is it from the python ext
// const activatePath = (
// condaPath ? path.join(path.dirname(condaPath), 'activate') : 'activate'
// ).fileToCommandArgumentForPythonExt(); // maybe global activate?
if (!condaActivateScriptCache) {
const activateScript = isWindows()
? path.join(condaFolder, 'Scripts', 'activate.bat')
: path.join(condaFolder, 'bin', 'activate');
if (!condaActivateScriptCache && (await fse.pathExists(activateScript))) {
// if activate script exists, default to using it
activateScriptPath = activateScript;
condaActivateScriptCache = activateScriptPath;
}
} else {
activateScriptPath = condaActivateScriptCache;
}

if (activateScriptPath) {
const sourcingCommand: PythonCommandRunConfiguration = { executable: 'source', args: [activateScriptPath] };

shellActivation.set(ShellConstants.GITBASH, [
sourcingCommand,
{ executable: 'conda', args: ['activate', name] },
]);
shellDeactivation.set(ShellConstants.GITBASH, [{ executable: 'conda', args: ['deactivate'] }]);

shellActivation.set(ShellConstants.CMD, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
shellDeactivation.set(ShellConstants.CMD, [{ executable: 'conda', args: ['deactivate'] }]);

shellActivation.set(ShellConstants.BASH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
shellDeactivation.set(ShellConstants.BASH, [{ executable: 'conda', args: ['deactivate'] }]);

shellActivation.set(ShellConstants.SH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
shellDeactivation.set(ShellConstants.SH, [{ executable: 'conda', args: ['deactivate'] }]);

shellActivation.set(ShellConstants.ZSH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
shellDeactivation.set(ShellConstants.ZSH, [{ executable: 'conda', args: ['deactivate'] }]);

shellActivation.set(ShellConstants.PWSH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
shellDeactivation.set(ShellConstants.PWSH, [{ executable: 'conda', args: ['deactivate'] }]);
} else if (conda.includes('/') || conda.includes('\\')) {
const shActivate = path.join(path.dirname(path.dirname(conda)), 'etc', 'profile.d', 'conda.sh');

if (isWindows()) {
Expand Down
Loading