@@ -280,13 +280,13 @@ function isPrefixOf(roots: string[], e: string): boolean {
280
280
return false ;
281
281
}
282
282
283
- function getNamedCondaPythonInfo (
283
+ async function getNamedCondaPythonInfo (
284
284
name : string ,
285
285
prefix : string ,
286
286
executable : string ,
287
287
version : string ,
288
288
conda : string ,
289
- ) : PythonEnvironmentInfo {
289
+ ) : Promise < PythonEnvironmentInfo > {
290
290
const sv = shortVersion ( version ) ;
291
291
const shellActivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
292
292
const shellDeactivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
@@ -323,7 +323,7 @@ function getNamedCondaPythonInfo(
323
323
] ) ;
324
324
shellDeactivation . set ( ShellConstants . ZSH , [ { executable : 'conda' , args : [ 'deactivate' ] } ] ) ;
325
325
}
326
- const psActivate = getCondaHookPs1Path ( conda ) ;
326
+ const psActivate = await getCondaHookPs1Path ( conda ) ;
327
327
shellActivation . set ( ShellConstants . PWSH , [
328
328
{ executable : '&' , args : [ psActivate ] } ,
329
329
{ executable : 'conda' , args : [ 'activate' , name ] } ,
@@ -374,12 +374,12 @@ function getNamedCondaPythonInfo(
374
374
} ;
375
375
}
376
376
377
- function getPrefixesCondaPythonInfo (
377
+ async function getPrefixesCondaPythonInfo (
378
378
prefix : string ,
379
379
executable : string ,
380
380
version : string ,
381
381
conda : string ,
382
- ) : PythonEnvironmentInfo {
382
+ ) : Promise < PythonEnvironmentInfo > {
383
383
const sv = shortVersion ( version ) ;
384
384
const shellActivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
385
385
const shellDeactivation : Map < string , PythonCommandRunConfiguration [ ] > = new Map ( ) ;
@@ -416,7 +416,7 @@ function getPrefixesCondaPythonInfo(
416
416
] ) ;
417
417
shellDeactivation . set ( ShellConstants . ZSH , [ { executable : 'conda' , args : [ 'deactivate' ] } ] ) ;
418
418
}
419
- const psActivate = getCondaHookPs1Path ( conda ) ;
419
+ const psActivate = await getCondaHookPs1Path ( conda ) ;
420
420
shellActivation . set ( ShellConstants . PWSH , [
421
421
{ executable : '&' , args : [ psActivate ] } ,
422
422
{ executable : 'conda' , args : [ 'activate' , prefix ] } ,
@@ -487,14 +487,14 @@ function getCondaWithoutPython(name: string, prefix: string, conda: string): Pyt
487
487
} ;
488
488
}
489
489
490
- function nativeToPythonEnv (
490
+ async function nativeToPythonEnv (
491
491
e : NativeEnvInfo ,
492
492
api : PythonEnvironmentApi ,
493
493
manager : EnvironmentManager ,
494
494
log : LogOutputChannel ,
495
495
conda : string ,
496
496
condaPrefixes : string [ ] ,
497
- ) : PythonEnvironment | undefined {
497
+ ) : Promise < PythonEnvironment | undefined > {
498
498
if ( ! ( e . prefix && e . executable && e . version ) ) {
499
499
let name = e . name ;
500
500
const environment = api . createPythonEnvironmentItem (
@@ -507,14 +507,14 @@ function nativeToPythonEnv(
507
507
508
508
if ( e . name === 'base' ) {
509
509
const environment = api . createPythonEnvironmentItem (
510
- getNamedCondaPythonInfo ( 'base' , e . prefix , e . executable , e . version , conda ) ,
510
+ await getNamedCondaPythonInfo ( 'base' , e . prefix , e . executable , e . version , conda ) ,
511
511
manager ,
512
512
) ;
513
513
log . info ( `Found base environment: ${ e . prefix } ` ) ;
514
514
return environment ;
515
515
} else if ( ! isPrefixOf ( condaPrefixes , e . prefix ) ) {
516
516
const environment = api . createPythonEnvironmentItem (
517
- getPrefixesCondaPythonInfo ( e . prefix , e . executable , e . version , conda ) ,
517
+ await getPrefixesCondaPythonInfo ( e . prefix , e . executable , e . version , conda ) ,
518
518
manager ,
519
519
) ;
520
520
log . info ( `Found prefix environment: ${ e . prefix } ` ) ;
@@ -523,7 +523,7 @@ function nativeToPythonEnv(
523
523
const basename = path . basename ( e . prefix ) ;
524
524
const name = e . name ?? basename ;
525
525
const environment = api . createPythonEnvironmentItem (
526
- getNamedCondaPythonInfo ( name , e . prefix , e . executable , e . version , conda ) ,
526
+ await getNamedCondaPythonInfo ( name , e . prefix , e . executable , e . version , conda ) ,
527
527
manager ,
528
528
) ;
529
529
log . info ( `Found named environment: ${ e . prefix } ` ) ;
@@ -586,8 +586,8 @@ export async function refreshCondaEnvs(
586
586
. filter ( ( e ) => e . kind === NativePythonEnvironmentKind . conda ) ;
587
587
const collection : PythonEnvironment [ ] = [ ] ;
588
588
589
- envs . forEach ( ( e ) => {
590
- const environment = nativeToPythonEnv ( e , api , manager , log , condaPath , condaPrefixes ) ;
589
+ envs . forEach ( async ( e ) => {
590
+ const environment = await nativeToPythonEnv ( e , api , manager , log , condaPath , condaPrefixes ) ;
591
591
if ( environment ) {
592
592
collection . push ( environment ) ;
593
593
}
@@ -699,7 +699,7 @@ async function createNamedCondaEnvironment(
699
699
const version = await getVersion ( envPath ) ;
700
700
701
701
const environment = api . createPythonEnvironmentItem (
702
- getNamedCondaPythonInfo ( envName , envPath , path . join ( envPath , bin ) , version , await getConda ( ) ) ,
702
+ await getNamedCondaPythonInfo ( envName , envPath , path . join ( envPath , bin ) , version , await getConda ( ) ) ,
703
703
manager ,
704
704
) ;
705
705
return environment ;
@@ -757,7 +757,7 @@ async function createPrefixCondaEnvironment(
757
757
const version = await getVersion ( prefix ) ;
758
758
759
759
const environment = api . createPythonEnvironmentItem (
760
- getPrefixesCondaPythonInfo ( prefix , path . join ( prefix , bin ) , version , await getConda ( ) ) ,
760
+ await getPrefixesCondaPythonInfo ( prefix , path . join ( prefix , bin ) , version , await getConda ( ) ) ,
761
761
manager ,
762
762
) ;
763
763
return environment ;
@@ -1062,25 +1062,32 @@ export async function checkForNoPythonCondaEnvironment(
1062
1062
* - condabin/
1063
1063
* - etc/profile.d/
1064
1064
*/
1065
- function getCondaHookPs1Path ( condaPath : string ) : string {
1065
+ async function getCondaHookPs1Path ( condaPath : string ) : Promise < string > {
1066
1066
const condaRoot = path . dirname ( path . dirname ( condaPath ) ) ;
1067
1067
1068
- let condaRootCandidates : string [ ] = [ ] ;
1069
- condaRootCandidates . push ( path . join ( condaRoot , 'shell' , 'condabin' ) ) ;
1070
- condaRootCandidates . push ( path . join ( condaRoot , 'Library' , 'shell' , 'condabin' ) ) ;
1071
- condaRootCandidates . push ( path . join ( condaRoot , 'condabin' ) ) ;
1072
- condaRootCandidates . push ( path . join ( condaRoot , 'etc' , 'profile.d' ) ) ;
1068
+ const condaRootCandidates : string [ ] = [
1069
+ path . join ( condaRoot , 'shell' , 'condabin' ) ,
1070
+ path . join ( condaRoot , 'Library' , 'shell' , 'condabin' ) ,
1071
+ path . join ( condaRoot , 'condabin' ) ,
1072
+ path . join ( condaRoot , 'etc' , 'profile.d' ) ,
1073
+ ] ;
1073
1074
1074
- for ( const hookSearchDir of condaRootCandidates ) {
1075
+ const checks = condaRootCandidates . map ( async ( hookSearchDir ) => {
1075
1076
const candidate = path . join ( hookSearchDir , 'conda-hook.ps1' ) ;
1076
- if ( fse . existsSync ( candidate ) ) {
1077
+ if ( await fse . pathExists ( candidate ) ) {
1077
1078
traceInfo ( `Conda hook found at: ${ candidate } ` ) ;
1078
1079
return candidate ;
1079
1080
}
1081
+ return undefined ;
1082
+ } ) ;
1083
+ const results = await Promise . all ( checks ) ;
1084
+ const found = results . find ( Boolean ) ;
1085
+ if ( found ) {
1086
+ return found as string ;
1080
1087
}
1081
1088
throw new Error (
1082
1089
`Conda hook not found in expected locations. Tried: ${ condaRootCandidates . join (
1083
1090
', ' ,
1084
1091
) } based on conda executable at ${ condaPath } .`,
1085
- ) ; // Throw an error if not found
1092
+ ) ;
1086
1093
}
0 commit comments