Skip to content

Commit 60c6059

Browse files
committed
add in initial check for activate script to mirror python ext behavior
1 parent c655ced commit 60c6059

1 file changed

Lines changed: 47 additions & 1 deletion

File tree

src/managers/conda/condaUtils.ts

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,7 @@ function isPrefixOf(roots: string[], e: string): boolean {
280280
return false;
281281
}
282282

283+
let condaActivateScriptCache: string | undefined = undefined;
283284
async function getNamedCondaPythonInfo(
284285
name: string,
285286
prefix: string,
@@ -291,7 +292,52 @@ async function getNamedCondaPythonInfo(
291292
const shellActivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
292293
const shellDeactivation: Map<string, PythonCommandRunConfiguration[]> = new Map();
293294

294-
if (conda.includes('/') || conda.includes('\\')) {
295+
let activateScriptPath = undefined;
296+
297+
// check if bin/activate script exists
298+
const condaFolder = path.dirname(path.dirname(conda));
299+
300+
// this is it from the python ext
301+
// const activatePath = (
302+
// condaPath ? path.join(path.dirname(condaPath), 'activate') : 'activate'
303+
// ).fileToCommandArgumentForPythonExt(); // maybe global activate?
304+
if (!condaActivateScriptCache) {
305+
const activateScript = isWindows()
306+
? path.join(condaFolder, 'Scripts', 'activate.bat')
307+
: path.join(condaFolder, 'bin', 'activate');
308+
if (!condaActivateScriptCache && (await fse.pathExists(activateScript))) {
309+
// if activate script exists, default to using it
310+
activateScriptPath = activateScript;
311+
condaActivateScriptCache = activateScriptPath;
312+
}
313+
} else {
314+
activateScriptPath = condaActivateScriptCache;
315+
}
316+
317+
if (activateScriptPath) {
318+
const sourcingCommand: PythonCommandRunConfiguration = { executable: 'source', args: [activateScriptPath] };
319+
320+
shellActivation.set(ShellConstants.GITBASH, [
321+
sourcingCommand,
322+
{ executable: 'conda', args: ['activate', name] },
323+
]);
324+
shellDeactivation.set(ShellConstants.GITBASH, [{ executable: 'conda', args: ['deactivate'] }]);
325+
326+
shellActivation.set(ShellConstants.CMD, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
327+
shellDeactivation.set(ShellConstants.CMD, [{ executable: 'conda', args: ['deactivate'] }]);
328+
329+
shellActivation.set(ShellConstants.BASH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
330+
shellDeactivation.set(ShellConstants.BASH, [{ executable: 'conda', args: ['deactivate'] }]);
331+
332+
shellActivation.set(ShellConstants.SH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
333+
shellDeactivation.set(ShellConstants.SH, [{ executable: 'conda', args: ['deactivate'] }]);
334+
335+
shellActivation.set(ShellConstants.ZSH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
336+
shellDeactivation.set(ShellConstants.ZSH, [{ executable: 'conda', args: ['deactivate'] }]);
337+
338+
shellActivation.set(ShellConstants.PWSH, [sourcingCommand, { executable: 'conda', args: ['activate', name] }]);
339+
shellDeactivation.set(ShellConstants.PWSH, [{ executable: 'conda', args: ['deactivate'] }]);
340+
} else if (conda.includes('/') || conda.includes('\\')) {
295341
const shActivate = path.join(path.dirname(path.dirname(conda)), 'etc', 'profile.d', 'conda.sh');
296342

297343
if (isWindows()) {

0 commit comments

Comments
 (0)