@@ -16,7 +16,7 @@ import { sleep } from '../../common/utils/async';
16
16
import { InMemoryCache } from '../../common/utils/cacheUtils' ;
17
17
import { OSType } from '../../common/utils/platform' ;
18
18
import { IEnvironmentVariablesProvider } from '../../common/variables/types' ;
19
- import { EnvironmentType , PythonEnvironment } from '../../pythonEnvironments/info' ;
19
+ import { PythonEnvironment } from '../../pythonEnvironments/info' ;
20
20
import { captureTelemetry , sendTelemetryEvent } from '../../telemetry' ;
21
21
import { EventName } from '../../telemetry/constants' ;
22
22
import { IInterpreterService } from '../contracts' ;
@@ -30,7 +30,6 @@ import {
30
30
traceVerbose ,
31
31
traceWarn ,
32
32
} from '../../logging' ;
33
- import { Conda } from '../../pythonEnvironments/common/environmentManagers/conda' ;
34
33
35
34
const ENVIRONMENT_PREFIX = 'e8b39361-0157-4923-80e1-22d70d46dee6' ;
36
35
const CACHE_DURATION = 10 * 60 * 1000 ;
@@ -170,41 +169,20 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
170
169
if ( ! shellInfo ) {
171
170
return ;
172
171
}
172
+ let isPossiblyCondaEnv = false ;
173
173
try {
174
- let command : string | undefined ;
175
- let [ args , parse ] = internalScripts . printEnvVariables ( ) ;
176
- args . forEach ( ( arg , i ) => {
177
- args [ i ] = arg . toCommandArgumentForPythonExt ( ) ;
178
- } ) ;
179
- interpreter = interpreter ?? ( await this . interpreterService . getActiveInterpreter ( resource ) ) ;
180
- if ( interpreter ?. envType === EnvironmentType . Conda ) {
181
- const conda = await Conda . getConda ( ) ;
182
- const pythonArgv = await conda ?. getRunPythonArgs ( {
183
- name : interpreter . envName ,
184
- prefix : interpreter . envPath ?? '' ,
185
- } ) ;
186
- if ( pythonArgv ) {
187
- // Using environment prefix isn't needed as the marker script already takes care of it.
188
- command = [ ...pythonArgv , ...args ] . map ( ( arg ) => arg . toCommandArgumentForPythonExt ( ) ) . join ( ' ' ) ;
189
- }
190
- }
191
- if ( ! command ) {
192
- const activationCommands = await this . helper . getEnvironmentActivationShellCommands (
193
- resource ,
194
- shellInfo . shellType ,
195
- interpreter ,
196
- ) ;
197
- traceVerbose ( `Activation Commands received ${ activationCommands } for shell ${ shellInfo . shell } ` ) ;
198
- if ( ! activationCommands || ! Array . isArray ( activationCommands ) || activationCommands . length === 0 ) {
199
- return ;
200
- }
201
- // Run the activate command collect the environment from it.
202
- const activationCommand = this . fixActivationCommands ( activationCommands ) . join ( ' && ' ) ;
203
- // In order to make sure we know where the environment output is,
204
- // put in a dummy echo we can look for
205
- command = `${ activationCommand } && echo '${ ENVIRONMENT_PREFIX } ' && python ${ args . join ( ' ' ) } ` ;
174
+ const activationCommands = await this . helper . getEnvironmentActivationShellCommands (
175
+ resource ,
176
+ shellInfo . shellType ,
177
+ interpreter ,
178
+ ) ;
179
+ traceVerbose ( `Activation Commands received ${ activationCommands } for shell ${ shellInfo . shell } ` ) ;
180
+ if ( ! activationCommands || ! Array . isArray ( activationCommands ) || activationCommands . length === 0 ) {
181
+ return ;
206
182
}
207
-
183
+ isPossiblyCondaEnv = activationCommands . join ( ' ' ) . toLowerCase ( ) . includes ( 'conda' ) ;
184
+ // Run the activate command collect the environment from it.
185
+ const activationCommand = this . fixActivationCommands ( activationCommands ) . join ( ' && ' ) ;
208
186
const processService = await this . processServiceFactory . create ( resource ) ;
209
187
const customEnvVars = await this . envVarsService . getEnvironmentVariables ( resource ) ;
210
188
const hasCustomEnvVars = Object . keys ( customEnvVars ) . length ;
@@ -216,6 +194,14 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
216
194
env [ PYTHON_WARNINGS ] = 'ignore' ;
217
195
218
196
traceVerbose ( `${ hasCustomEnvVars ? 'Has' : 'No' } Custom Env Vars` ) ;
197
+
198
+ // In order to make sure we know where the environment output is,
199
+ // put in a dummy echo we can look for
200
+ const [ args , parse ] = internalScripts . printEnvVariables ( ) ;
201
+ args . forEach ( ( arg , i ) => {
202
+ args [ i ] = arg . toCommandArgumentForPythonExt ( ) ;
203
+ } ) ;
204
+ const command = `${ activationCommand } && echo '${ ENVIRONMENT_PREFIX } ' && python ${ args . join ( ' ' ) } ` ;
219
205
traceVerbose ( `Activating Environment to capture Environment variables, ${ command } ` ) ;
220
206
221
207
// Do some wrapping of the call. For two reasons:
@@ -233,10 +219,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
233
219
result = await processService . shellExec ( command , {
234
220
env,
235
221
shell : shellInfo . shell ,
236
- timeout :
237
- interpreter ?. envType === EnvironmentType . Conda
238
- ? CONDA_ENVIRONMENT_TIMEOUT
239
- : ENVIRONMENT_TIMEOUT ,
222
+ timeout : isPossiblyCondaEnv ? CONDA_ENVIRONMENT_TIMEOUT : ENVIRONMENT_TIMEOUT ,
240
223
maxBuffer : 1000 * 1000 ,
241
224
throwOnStdErr : false ,
242
225
} ) ;
@@ -282,7 +265,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
282
265
} catch ( e ) {
283
266
traceError ( 'getActivatedEnvironmentVariables' , e ) ;
284
267
sendTelemetryEvent ( EventName . ACTIVATE_ENV_TO_GET_ENV_VARS_FAILED , undefined , {
285
- isPossiblyCondaEnv : interpreter ?. envType === EnvironmentType . Conda ,
268
+ isPossiblyCondaEnv,
286
269
terminal : shellInfo . shellType ,
287
270
} ) ;
288
271
@@ -300,9 +283,6 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
300
283
@traceDecoratorError ( 'Failed to parse Environment variables' )
301
284
@traceDecoratorVerbose ( 'parseEnvironmentOutput' , TraceOptions . None )
302
285
protected parseEnvironmentOutput ( output : string , parse : ( out : string ) => NodeJS . ProcessEnv | undefined ) {
303
- if ( output . indexOf ( ENVIRONMENT_PREFIX ) === - 1 ) {
304
- return parse ( output ) ;
305
- }
306
286
output = output . substring ( output . indexOf ( ENVIRONMENT_PREFIX ) + ENVIRONMENT_PREFIX . length ) ;
307
287
const js = output . substring ( output . indexOf ( '{' ) ) . trim ( ) ;
308
288
return parse ( js ) ;
0 commit comments