@@ -107,15 +107,29 @@ pub fn get_environments(conda_dir: &Path) -> Vec<PathBuf> {
107
107
envs. push ( conda_dir. to_path_buf ( ) ) ;
108
108
109
109
if let Ok ( entries) = fs:: read_dir ( conda_dir. join ( "envs" ) ) {
110
- for entry in entries. filter_map ( Result :: ok) {
111
- let path = entry. path ( ) ;
112
- if is_conda_env ( & path) {
113
- envs. push ( path) ;
114
- }
115
- }
110
+ envs. append (
111
+ & mut entries
112
+ . filter_map ( Result :: ok)
113
+ . map ( |e| e. path ( ) )
114
+ . filter ( |p| is_conda_env ( p) )
115
+ . collect ( ) ,
116
+ ) ;
116
117
}
117
118
} else if is_conda_env ( conda_dir) {
118
119
envs. push ( conda_dir. to_path_buf ( ) ) ;
120
+ } else if fs:: metadata ( conda_dir. join ( "envs" ) ) . is_ok ( ) {
121
+ // This could be a directory where conda environments are stored.
122
+ // I.e. its not necessarily the root conda install directory.
123
+ // E.g. C:\Users\donjayamanne\.conda
124
+ if let Ok ( entries) = fs:: read_dir ( conda_dir. join ( "envs" ) ) {
125
+ envs. append (
126
+ & mut entries
127
+ . filter_map ( Result :: ok)
128
+ . map ( |e| e. path ( ) )
129
+ . filter ( |p| is_conda_env ( p) )
130
+ . collect ( ) ,
131
+ ) ;
132
+ }
119
133
}
120
134
121
135
envs. sort ( ) ;
@@ -161,33 +175,73 @@ pub fn get_known_conda_install_locations(env_vars: &EnvVariables) -> Vec<PathBuf
161
175
known_paths. push ( Path :: new ( & home_drive) . join ( "miniconda" ) ) ;
162
176
known_paths. push ( Path :: new ( & home_drive) . join ( "miniforge3" ) ) ;
163
177
}
178
+ if let Some ( ref conda_root) = env_vars. conda_root {
179
+ known_paths. push ( PathBuf :: from ( conda_root. clone ( ) ) ) ;
180
+ }
181
+ if let Some ( ref conda_prefix) = env_vars. conda_prefix {
182
+ known_paths. push ( PathBuf :: from ( conda_prefix. clone ( ) ) ) ;
183
+ }
184
+ if let Some ( ref conda) = env_vars. conda {
185
+ let conda = PathBuf :: from ( conda) ;
186
+ if let Some ( parent) = conda. parent ( ) {
187
+ known_paths. push ( parent. to_path_buf ( ) ) ;
188
+ }
189
+ }
164
190
if let Some ( home) = env_vars. clone ( ) . home {
165
191
known_paths. push ( home. clone ( ) . join ( "anaconda3" ) ) ;
166
192
known_paths. push ( home. clone ( ) . join ( "miniconda3" ) ) ;
167
193
known_paths. push ( home. clone ( ) . join ( "miniforge3" ) ) ;
194
+ // E.g. C:\Users\user name\.conda where we have `envs`` under this directory.
168
195
known_paths. push ( home. join ( ".conda" ) ) ;
196
+ // E.g. C:\Users\user name\AppData\Local\conda\conda\envs
197
+ known_paths. push (
198
+ home. join ( "AppData" )
199
+ . join ( "Local" )
200
+ . join ( "conda" )
201
+ . join ( "conda" ) ,
202
+ ) ;
169
203
}
204
+ known_paths. sort ( ) ;
205
+ known_paths. dedup ( ) ;
170
206
known_paths
171
207
}
172
208
173
209
#[ cfg( unix) ]
174
210
pub fn get_known_conda_install_locations ( env_vars : & EnvVariables ) -> Vec < PathBuf > {
175
- let mut known_paths = vec ! [
176
- PathBuf :: from( "/opt/anaconda3" ) ,
177
- PathBuf :: from( "/opt/miniconda3" ) ,
178
- PathBuf :: from( "/usr/local/anaconda3" ) ,
179
- PathBuf :: from( "/usr/local/miniconda3" ) ,
180
- PathBuf :: from( "/usr/anaconda3" ) ,
181
- PathBuf :: from( "/usr/miniconda3" ) ,
182
- PathBuf :: from( "/home/anaconda3" ) ,
183
- PathBuf :: from( "/home/miniconda3" ) ,
184
- PathBuf :: from( "/anaconda3" ) ,
185
- PathBuf :: from( "/miniconda3" ) ,
186
- PathBuf :: from( "/miniforge3" ) ,
187
- PathBuf :: from( "/miniforge3" ) ,
211
+ let mut known_paths = vec ! [ ] ;
212
+ let directories_to_look_in = [
213
+ "/opt" ,
214
+ "/opt" ,
215
+ "/usr/share" ,
216
+ "/usr/local" ,
217
+ "/usr" ,
218
+ "/home" ,
219
+ "" , // We need to look in `/anaconda3` and `/miniconda3` as well.
188
220
] ;
221
+ for directory in directories_to_look_in. iter ( ) {
222
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/anaconda" , directory) ) ) ;
223
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/anaconda3" , directory) ) ) ;
224
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/miniconda" , directory) ) ) ;
225
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/miniconda3" , directory) ) ) ;
226
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/miniforge" , directory) ) ) ;
227
+ known_paths. push ( PathBuf :: from ( format ! ( "{}/miniforge3" , directory) ) ) ;
228
+ }
229
+ if let Some ( ref conda_root) = env_vars. conda_root {
230
+ known_paths. push ( PathBuf :: from ( conda_root. clone ( ) ) ) ;
231
+ }
232
+ if let Some ( ref conda_prefix) = env_vars. conda_prefix {
233
+ known_paths. push ( PathBuf :: from ( conda_prefix. clone ( ) ) ) ;
234
+ }
235
+ if let Some ( ref conda) = env_vars. conda {
236
+ let conda = PathBuf :: from ( conda) ;
237
+ if let Some ( parent) = conda. parent ( ) {
238
+ known_paths. push ( parent. to_path_buf ( ) ) ;
239
+ }
240
+ }
189
241
if let Some ( ref home) = env_vars. home {
242
+ known_paths. push ( home. clone ( ) . join ( "anaconda" ) ) ;
190
243
known_paths. push ( home. clone ( ) . join ( "anaconda3" ) ) ;
244
+ known_paths. push ( home. clone ( ) . join ( "miniconda" ) ) ;
191
245
known_paths. push ( home. clone ( ) . join ( "miniconda3" ) ) ;
192
246
known_paths. push ( home. clone ( ) . join ( "miniforge3" ) ) ;
193
247
known_paths. push ( home. join ( ".conda" ) ) ;
0 commit comments