@@ -55,6 +55,7 @@ public sealed class CondaEnvironment: PythonEnvironment {
55
55
CancellationToken cancellation = default )
56
56
=> GetEnvironmentRoots ( cancellation )
57
57
. SelectMany ( home => {
58
+ cancellation . ThrowIfCancellationRequested ( ) ;
58
59
var environment = DetectCondaEnvironment ( home , cancellation ) ;
59
60
return environment is null
60
61
? Array . Empty < CondaEnvironment > ( )
@@ -64,14 +65,23 @@ public sealed class CondaEnvironment: PythonEnvironment {
64
65
static IEnumerable < DirectoryInfo > GetEnvironmentRoots ( CancellationToken cancellation ) {
65
66
string userHome = Environment . GetFolderPath ( Environment . SpecialFolder . UserProfile ) ;
66
67
string condaEnvironmentsFilePath = Path . Combine ( userHome , ".conda" , "environments.txt" ) ;
67
- if ( ! File . Exists ( condaEnvironmentsFilePath ) )
68
- yield break ;
68
+ if ( File . Exists ( condaEnvironmentsFilePath ) ) {
69
+ foreach ( var potentialRoot in ReadEnvironmentRootsFile ( condaEnvironmentsFilePath ) )
70
+ yield return potentialRoot ;
71
+ }
69
72
70
73
cancellation . ThrowIfCancellationRequested ( ) ;
71
74
75
+ if ( RuntimeInformation . IsOSPlatform ( OSPlatform . Windows ) ) {
76
+ foreach ( var potentialRoot in GetSystemWideEnvironmentRoots ( cancellation ) )
77
+ yield return potentialRoot ;
78
+ }
79
+ }
80
+
81
+ static IEnumerable < DirectoryInfo > ReadEnvironmentRootsFile ( string filePath ) {
72
82
string [ ] pythonHomes ;
73
83
try {
74
- pythonHomes = File . ReadAllLines ( condaEnvironmentsFilePath ) ;
84
+ pythonHomes = File . ReadAllLines ( filePath ) ;
75
85
}
76
86
catch ( FileNotFoundException ) { yield break ; }
77
87
catch ( DirectoryNotFoundException ) { yield break ; }
@@ -84,6 +94,18 @@ static IEnumerable<DirectoryInfo> GetEnvironmentRoots(CancellationToken cancella
84
94
}
85
95
}
86
96
97
+ static IEnumerable < DirectoryInfo > GetSystemWideEnvironmentRoots ( CancellationToken cancellation ) {
98
+ string systemWideEnvironmentsPath = Path . Combine (
99
+ Environment . GetFolderPath ( Environment . SpecialFolder . CommonApplicationData ) ,
100
+ "Anaconda3" ,
101
+ "envs"
102
+ ) ;
103
+ var systemWideEnvironmentsDir = new DirectoryInfo ( systemWideEnvironmentsPath ) ;
104
+ return systemWideEnvironmentsDir . Exists
105
+ ? systemWideEnvironmentsDir . EnumerateDirectories ( )
106
+ : Array . Empty < DirectoryInfo > ( ) ;
107
+ }
108
+
87
109
CondaEnvironment ( FileInfo interpreterPath , DirectoryInfo home , FileInfo ? dll , Version ? languageVersion , Architecture ? architecture ) : base ( interpreterPath , home , dll , languageVersion , architecture ) { }
88
110
}
89
111
}
0 commit comments