@@ -186,6 +186,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
186
186
if ( ! shellInfo ) {
187
187
return ;
188
188
}
189
+ let isPossiblyCondaEnv = false ;
189
190
try {
190
191
let command : string | undefined ;
191
192
let [ args , parse ] = internalScripts . printEnvVariables ( ) ;
@@ -203,23 +204,9 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
203
204
command = [ ...pythonArgv , ...args ] . map ( ( arg ) => arg . toCommandArgumentForPythonExt ( ) ) . join ( ' ' ) ;
204
205
}
205
206
}
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 ( ' && ' ) ;
223
210
const processService = await this . processServiceFactory . create ( resource ) ;
224
211
const customEnvVars = await this . envVarsService . getEnvironmentVariables ( resource ) ;
225
212
const hasCustomEnvVars = Object . keys ( customEnvVars ) . length ;
@@ -231,6 +218,14 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
231
218
env [ PYTHON_WARNINGS ] = 'ignore' ;
232
219
233
220
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 ( ' ' ) } ` ;
234
229
traceVerbose ( `Activating Environment to capture Environment variables, ${ command } ` ) ;
235
230
236
231
// Do some wrapping of the call. For two reasons:
@@ -248,10 +243,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
248
243
result = await processService . shellExec ( command , {
249
244
env,
250
245
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 ,
255
247
maxBuffer : 1000 * 1000 ,
256
248
throwOnStdErr : false ,
257
249
} ) ;
@@ -297,7 +289,7 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
297
289
} catch ( e ) {
298
290
traceError ( 'getActivatedEnvironmentVariables' , e ) ;
299
291
sendTelemetryEvent ( EventName . ACTIVATE_ENV_TO_GET_ENV_VARS_FAILED , undefined , {
300
- isPossiblyCondaEnv : interpreter ?. envType === EnvironmentType . Conda ,
292
+ isPossiblyCondaEnv,
301
293
terminal : shellInfo . shellType ,
302
294
} ) ;
303
295
@@ -315,9 +307,6 @@ export class EnvironmentActivationService implements IEnvironmentActivationServi
315
307
@traceDecoratorError ( 'Failed to parse Environment variables' )
316
308
@traceDecoratorVerbose ( 'parseEnvironmentOutput' , TraceOptions . None )
317
309
protected parseEnvironmentOutput ( output : string , parse : ( out : string ) => NodeJS . ProcessEnv | undefined ) {
318
- if ( output . indexOf ( ENVIRONMENT_PREFIX ) === - 1 ) {
319
- return parse ( output ) ;
320
- }
321
310
output = output . substring ( output . indexOf ( ENVIRONMENT_PREFIX ) + ENVIRONMENT_PREFIX . length ) ;
322
311
const js = output . substring ( output . indexOf ( '{' ) ) . trim ( ) ;
323
312
return parse ( js ) ;
0 commit comments