Skip to content

Commit fec1b06

Browse files
authored
Add verbose logging for conda activation commands and service methods (#25365)
to assist with transition to python-environments extension, add in verbose logging to help track existing steps while debugging
1 parent f3f2293 commit fec1b06

File tree

2 files changed

+27
-4
lines changed

2 files changed

+27
-4
lines changed

src/client/common/terminal/environmentActivationProviders/condaActivationProvider.ts

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import '../../extensions';
88
import { inject, injectable } from 'inversify';
99
import * as path from 'path';
1010
import { Uri } from 'vscode';
11+
import { traceInfo, traceVerbose, traceWarn } from '../../../logging';
1112

1213
import { IComponentAdapter, ICondaService } from '../../../interpreter/contracts';
1314
import { IPlatformService } from '../../platform/types';
@@ -53,28 +54,36 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
5354
pythonPath: string,
5455
targetShell: TerminalShellType,
5556
): Promise<string[] | undefined> {
57+
traceVerbose(`Getting conda activation commands for interpreter ${pythonPath} with shell ${targetShell}`);
5658
const envInfo = await this.pyenvs.getCondaEnvironment(pythonPath);
5759
if (!envInfo) {
60+
traceWarn(`No conda environment found for interpreter ${pythonPath}`);
5861
return undefined;
5962
}
63+
traceVerbose(`Found conda environment: ${JSON.stringify(envInfo)}`);
6064

6165
const condaEnv = envInfo.name.length > 0 ? envInfo.name : envInfo.path;
6266

6367
// New version.
6468
const interpreterPath = await this.condaService.getInterpreterPathForEnvironment(envInfo);
69+
traceInfo(`Using interpreter path: ${interpreterPath}`);
6570
const activatePath = await this.condaService.getActivationScriptFromInterpreter(interpreterPath, envInfo.name);
71+
traceVerbose(`Got activation script: ${activatePath?.path}} with type: ${activatePath?.type}`);
6672
// eslint-disable-next-line camelcase
6773
if (activatePath?.path) {
6874
if (
6975
this.platform.isWindows &&
7076
targetShell !== TerminalShellType.bash &&
7177
targetShell !== TerminalShellType.gitbash
7278
) {
73-
return [activatePath.path, `conda activate ${condaEnv.toCommandArgumentForPythonExt()}`];
79+
const commands = [activatePath.path, `conda activate ${condaEnv.toCommandArgumentForPythonExt()}`];
80+
traceInfo(`Using Windows-specific commands: ${commands.join(', ')}`);
81+
return commands;
7482
}
7583

7684
const condaInfo = await this.condaService.getCondaInfo();
7785

86+
traceVerbose(`Conda shell level: ${condaInfo?.conda_shlvl}`);
7887
if (
7988
activatePath.type !== 'global' ||
8089
// eslint-disable-next-line camelcase
@@ -84,27 +93,36 @@ export class CondaActivationCommandProvider implements ITerminalActivationComman
8493
// activatePath is not the global activate path, or we don't have a shlvl, or it's -1(conda never sourced).
8594
// and we need to source the activate path.
8695
if (activatePath.path === 'activate') {
87-
return [
96+
const commands = [
8897
`source ${activatePath.path}`,
8998
`conda activate ${condaEnv.toCommandArgumentForPythonExt()}`,
9099
];
100+
traceInfo(`Using source activate commands: ${commands.join(', ')}`);
101+
return commands;
91102
}
92-
return [`source ${activatePath.path} ${condaEnv.toCommandArgumentForPythonExt()}`];
103+
const command = [`source ${activatePath.path} ${condaEnv.toCommandArgumentForPythonExt()}`];
104+
traceInfo(`Using single source command: ${command}`);
105+
return command;
93106
}
94-
return [`conda activate ${condaEnv.toCommandArgumentForPythonExt()}`];
107+
const command = [`conda activate ${condaEnv.toCommandArgumentForPythonExt()}`];
108+
traceInfo(`Using direct conda activate command: ${command}`);
109+
return command;
95110
}
96111

97112
switch (targetShell) {
98113
case TerminalShellType.powershell:
99114
case TerminalShellType.powershellCore:
115+
traceVerbose('Using PowerShell-specific activation');
100116
return _getPowershellCommands(condaEnv);
101117

102118
// TODO: Do we really special-case fish on Windows?
103119
case TerminalShellType.fish:
120+
traceVerbose('Using Fish shell-specific activation');
104121
return getFishCommands(condaEnv, await this.condaService.getCondaFile());
105122

106123
default:
107124
if (this.platform.isWindows) {
125+
traceVerbose('Using Windows shell-specific activation fallback option.');
108126
return this.getWindowsCommands(condaEnv);
109127
}
110128
return getUnixCommands(condaEnv, await this.condaService.getCondaFile());

src/client/pythonEnvironments/common/environmentManagers/condaService.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { inject, injectable } from 'inversify';
22
import * as path from 'path';
33
import { SemVer } from 'semver';
44
import { IFileSystem, IPlatformService } from '../../../common/platform/types';
5+
import { traceVerbose } from '../../../logging';
56
import { cache } from '../../../common/utils/decorators';
67
import { ICondaService } from '../../../interpreter/contracts';
78
import { traceDecoratorVerbose } from '../../../logging';
@@ -23,12 +24,15 @@ export class CondaService implements ICondaService {
2324
interpreterPath?: string,
2425
envName?: string,
2526
): Promise<{ path: string | undefined; type: 'local' | 'global' } | undefined> {
27+
traceVerbose(`Getting activation script for interpreter ${interpreterPath}, env ${envName}`);
2628
const condaPath = await this.getCondaFileFromInterpreter(interpreterPath, envName);
29+
traceVerbose(`Found conda path: ${condaPath}`);
2730

2831
const activatePath = (condaPath
2932
? path.join(path.dirname(condaPath), 'activate')
3033
: 'activate'
3134
).fileToCommandArgumentForPythonExt(); // maybe global activate?
35+
traceVerbose(`Using activate path: ${activatePath}`);
3236

3337
// try to find the activate script in the global conda root prefix.
3438
if (this.platform.isLinux || this.platform.isMac) {
@@ -41,6 +45,7 @@ export class CondaService implements ICondaService {
4145
.fileToCommandArgumentForPythonExt();
4246

4347
if (activatePath === globalActivatePath || !(await this.fileSystem.fileExists(activatePath))) {
48+
traceVerbose(`Using global activate path: ${globalActivatePath}`);
4449
return {
4550
path: globalActivatePath,
4651
type: 'global',

0 commit comments

Comments
 (0)