diff --git a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts index d209550e04a4..42bb8f38fc9e 100644 --- a/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts +++ b/src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts @@ -8,6 +8,7 @@ import '../../extensions'; import { inject, injectable } from 'inversify'; import * as path from 'path'; import { Uri } from 'vscode'; +import { traceInfo, traceVerbose, traceWarn } from '../../../logging'; import { IComponentAdapter, ICondaService } from '../../../interpreter/contracts'; import { IPlatformService } from '../../platform/types'; @@ -53,16 +54,21 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman pythonPath: string, targetShell: TerminalShellType, ): Promise { + traceVerbose(`Getting conda activation commands for interpreter ${pythonPath} with shell ${targetShell}`); const envInfo = await this.pyenvs.getCondaEnvironment(pythonPath); if (!envInfo) { + traceWarn(`No conda environment found for interpreter ${pythonPath}`); return undefined; } + traceVerbose(`Found conda environment: ${JSON.stringify(envInfo)}`); const condaEnv = envInfo.name.length > 0 ? envInfo.name : envInfo.path; // New version. const interpreterPath = await this.condaService.getInterpreterPathForEnvironment(envInfo); + traceInfo(`Using interpreter path: ${interpreterPath}`); const activatePath = await this.condaService.getActivationScriptFromInterpreter(interpreterPath, envInfo.name); + traceVerbose(`Got activation script: ${activatePath?.path}} with type: ${activatePath?.type}`); // eslint-disable-next-line camelcase if (activatePath?.path) { if ( @@ -70,11 +76,14 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman targetShell !== TerminalShellType.bash && targetShell !== TerminalShellType.gitbash ) { - return [activatePath.path, `conda activate ${condaEnv.toCommandArgumentForPythonExt()}`]; + const commands = [activatePath.path, `conda activate ${condaEnv.toCommandArgumentForPythonExt()}`]; + traceInfo(`Using Windows-specific commands: ${commands.join(', ')}`); + return commands; } const condaInfo = await this.condaService.getCondaInfo(); + traceVerbose(`Conda shell level: ${condaInfo?.conda_shlvl}`); if ( activatePath.type !== 'global' || // eslint-disable-next-line camelcase @@ -84,27 +93,36 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman // activatePath is not the global activate path, or we don't have a shlvl, or it's -1(conda never sourced). // and we need to source the activate path. if (activatePath.path === 'activate') { - return [ + const commands = [ `source ${activatePath.path}`, `conda activate ${condaEnv.toCommandArgumentForPythonExt()}`, ]; + traceInfo(`Using source activate commands: ${commands.join(', ')}`); + return commands; } - return [`source ${activatePath.path} ${condaEnv.toCommandArgumentForPythonExt()}`]; + const command = [`source ${activatePath.path} ${condaEnv.toCommandArgumentForPythonExt()}`]; + traceInfo(`Using single source command: ${command}`); + return command; } - return [`conda activate ${condaEnv.toCommandArgumentForPythonExt()}`]; + const command = [`conda activate ${condaEnv.toCommandArgumentForPythonExt()}`]; + traceInfo(`Using direct conda activate command: ${command}`); + return command; } switch (targetShell) { case TerminalShellType.powershell: case TerminalShellType.powershellCore: + traceVerbose('Using PowerShell-specific activation'); return _getPowershellCommands(condaEnv); // TODO: Do we really special-case fish on Windows? case TerminalShellType.fish: + traceVerbose('Using Fish shell-specific activation'); return getFishCommands(condaEnv, await this.condaService.getCondaFile()); default: if (this.platform.isWindows) { + traceVerbose('Using Windows shell-specific activation fallback option.'); return this.getWindowsCommands(condaEnv); } return getUnixCommands(condaEnv, await this.condaService.getCondaFile()); diff --git a/src/client/pythonEnvironments/common/environmentManagers/condaService.ts b/src/client/pythonEnvironments/common/environmentManagers/condaService.ts index 0739993dad37..0aa91bdbfb45 100644 --- a/src/client/pythonEnvironments/common/environmentManagers/condaService.ts +++ b/src/client/pythonEnvironments/common/environmentManagers/condaService.ts @@ -2,6 +2,7 @@ import { inject, injectable } from 'inversify'; import * as path from 'path'; import { SemVer } from 'semver'; import { IFileSystem, IPlatformService } from '../../../common/platform/types'; +import { traceVerbose } from '../../../logging'; import { cache } from '../../../common/utils/decorators'; import { ICondaService } from '../../../interpreter/contracts'; import { traceDecoratorVerbose } from '../../../logging'; @@ -23,12 +24,15 @@ export class CondaService implements ICondaService { interpreterPath?: string, envName?: string, ): Promise<{ path: string | undefined; type: 'local' | 'global' } | undefined> { + traceVerbose(`Getting activation script for interpreter ${interpreterPath}, env ${envName}`); const condaPath = await this.getCondaFileFromInterpreter(interpreterPath, envName); + traceVerbose(`Found conda path: ${condaPath}`); const activatePath = (condaPath ? path.join(path.dirname(condaPath), 'activate') : 'activate' ).fileToCommandArgumentForPythonExt(); // maybe global activate? + traceVerbose(`Using activate path: ${activatePath}`); // try to find the activate script in the global conda root prefix. if (this.platform.isLinux || this.platform.isMac) { @@ -41,6 +45,7 @@ export class CondaService implements ICondaService { .fileToCommandArgumentForPythonExt(); if (activatePath === globalActivatePath || !(await this.fileSystem.fileExists(activatePath))) { + traceVerbose(`Using global activate path: ${globalActivatePath}`); return { path: globalActivatePath, type: 'global',