Skip to content

Commit 3e2f1c9

Browse files
Kartik Rajeleanorjboyd
authored andcommitted
continue
1 parent 7fd8315 commit 3e2f1c9

File tree

2 files changed

+17
-29
lines changed

2 files changed

+17
-29
lines changed

src/client/interpreter/activation/service.ts

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
186186
if (!shellInfo) {
187187
return;
188188
}
189+
let isPossiblyCondaEnv = false;
189190
try {
190191
let command: string | undefined;
191192
let [args, parse] = internalScripts.printEnvVariables();
@@ -203,23 +204,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
203204
command = [...pythonArgv, ...args].map((arg) => arg.toCommandArgumentForPythonExt()).join(' ');
204205
}
205206
}
206-
if (!command) {
207-
const activationCommands = await this.helper.getEnvironmentActivationShellCommands(
208-
resource,
209-
shellInfo.shellType,
210-
interpreter,
211-
);
212-
traceVerbose(`Activation Commands received ${activationCommands} for shell ${shellInfo.shell}`);
213-
if (!activationCommands || !Array.isArray(activationCommands) || activationCommands.length === 0) {
214-
return;
215-
}
216-
// Run the activate command collect the environment from it.
217-
const activationCommand = this.fixActivationCommands(activationCommands).join(' && ');
218-
// In order to make sure we know where the environment output is,
219-
// put in a dummy echo we can look for
220-
command = `${activationCommand} && echo '${ENVIRONMENT_PREFIX}' && python ${args.join(' ')}`;
221-
}
222-
207+
isPossiblyCondaEnv = activationCommands.join(' ').toLowerCase().includes('conda');
208+
// Run the activate command collect the environment from it.
209+
const activationCommand = this.fixActivationCommands(activationCommands).join(' && ');
223210
const processService = await this.processServiceFactory.create(resource);
224211
const customEnvVars = await this.envVarsService.getEnvironmentVariables(resource);
225212
const hasCustomEnvVars = Object.keys(customEnvVars).length;
@@ -231,6 +218,14 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
231218
env[PYTHON_WARNINGS] = 'ignore';
232219

233220
traceVerbose(`${hasCustomEnvVars ? 'Has' : 'No'} Custom Env Vars`);
221+
222+
// In order to make sure we know where the environment output is,
223+
// put in a dummy echo we can look for
224+
const [args, parse] = internalScripts.printEnvVariables();
225+
args.forEach((arg, i) => {
226+
args[i] = arg.toCommandArgumentForPythonExt();
227+
});
228+
const command = `${activationCommand} && echo '${ENVIRONMENT_PREFIX}' && python ${args.join(' ')}`;
234229
traceVerbose(`Activating Environment to capture Environment variables, ${command}`);
235230

236231
// Do some wrapping of the call. For two reasons:
@@ -248,10 +243,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
248243
result = await processService.shellExec(command, {
249244
env,
250245
shell: shellInfo.shell,
251-
timeout:
252-
interpreter?.envType === EnvironmentType.Conda
253-
? CONDA_ENVIRONMENT_TIMEOUT
254-
: ENVIRONMENT_TIMEOUT,
246+
timeout: isPossiblyCondaEnv ? CONDA_ENVIRONMENT_TIMEOUT : ENVIRONMENT_TIMEOUT,
255247
maxBuffer: 1000 * 1000,
256248
throwOnStdErr: false,
257249
});
@@ -297,7 +289,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
297289
} catch (e) {
298290
traceError('getActivatedEnvironmentVariables', e);
299291
sendTelemetryEvent(EventName.ACTIVATE_ENV_TO_GET_ENV_VARS_FAILED, undefined, {
300-
isPossiblyCondaEnv: interpreter?.envType === EnvironmentType.Conda,
292+
isPossiblyCondaEnv,
301293
terminal: shellInfo.shellType,
302294
});
303295

@@ -315,9 +307,6 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
315307
@traceDecoratorError('Failed to parse Environment variables')
316308
@traceDecoratorVerbose('parseEnvironmentOutput', TraceOptions.None)
317309
protected parseEnvironmentOutput(output: string, parse: (out: string) => NodeJS.ProcessEnv | undefined) {
318-
if (output.indexOf(ENVIRONMENT_PREFIX) === -1) {
319-
return parse(output);
320-
}
321310
output = output.substring(output.indexOf(ENVIRONMENT_PREFIX) + ENVIRONMENT_PREFIX.length);
322311
const js = output.substring(output.indexOf('{')).trim();
323312
return parse(js);

src/test/interpreters/activation/service.unit.test.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ suite('Interpreters Activation - Python Environment Variables', () => {
5858
architecture: Architecture.x64,
5959
};
6060

61-
function initSetup(interpreter: PythonEnvironment | undefined) {
61+
function initSetup() {
6262
helper = mock(TerminalHelper);
6363
platform = mock(PlatformService);
6464
processServiceFactory = mock(ProcessServiceFactory);
@@ -71,7 +71,6 @@ suite('Interpreters Activation - Python Environment Variables', () => {
7171
onDidChangeInterpreter = new EventEmitter<void>();
7272
when(envVarsService.onDidEnvironmentVariablesChange).thenReturn(onDidChangeEnvVariables.event);
7373
when(interpreterService.onDidChangeInterpreter).thenReturn(onDidChangeInterpreter.event);
74-
when(interpreterService.getActiveInterpreter(anything())).thenResolve(interpreter);
7574
service = new EnvironmentActivationService(
7675
instance(helper),
7776
instance(platform),
@@ -90,7 +89,7 @@ suite('Interpreters Activation - Python Environment Variables', () => {
9089
[undefined, Uri.parse('a')].forEach((resource) =>
9190
[undefined, pythonInterpreter].forEach((interpreter) => {
9291
suite(title(resource, interpreter), () => {
93-
setup(() => initSetup(interpreter));
92+
setup(initSetup);
9493
test('Unknown os will return empty variables', async () => {
9594
when(platform.osType).thenReturn(OSType.Unknown);
9695
const env = await service.getActivatedEnvironmentVariables(resource);
@@ -103,7 +102,7 @@ suite('Interpreters Activation - Python Environment Variables', () => {
103102

104103
osTypes.forEach((osType) => {
105104
suite(osType.name, () => {
106-
setup(() => initSetup(interpreter));
105+
setup(initSetup);
107106
test('getEnvironmentActivationShellCommands will be invoked', async () => {
108107
when(platform.osType).thenReturn(osType.value);
109108
when(

0 commit comments

Comments
 (0)