4
4
use conda_info:: CondaInfo ;
5
5
use env_variables:: EnvVariables ;
6
6
use environment_locations:: {
7
- get_conda_environment_paths, get_conda_envs_from_environment_txt, get_environments,
7
+ get_conda_dir_from_exe, get_conda_environment_paths, get_conda_envs_from_environment_txt,
8
+ get_environments,
8
9
} ;
9
10
use environments:: { get_conda_environment_info, CondaEnvironment } ;
10
11
use log:: error;
@@ -15,6 +16,7 @@ use pet_core::{
15
16
reporter:: Reporter ,
16
17
Locator ,
17
18
} ;
19
+ use pet_fs:: path:: norm_case;
18
20
use pet_python_utils:: env:: PythonEnv ;
19
21
use serde:: { Deserialize , Serialize } ;
20
22
use std:: {
@@ -54,13 +56,15 @@ pub struct CondaTelemetryInfo {
54
56
pub env_dirs : Vec < PathBuf > ,
55
57
pub environments_txt : Option < PathBuf > ,
56
58
pub environments_txt_exists : Option < bool > ,
59
+ pub user_provided_env_found : Option < bool > ,
57
60
pub environments_from_txt : Vec < PathBuf > ,
58
61
}
59
62
60
63
pub struct Conda {
61
64
pub environments : Arc < Mutex < HashMap < PathBuf , PythonEnvironment > > > ,
62
65
pub managers : Arc < Mutex < HashMap < PathBuf , CondaManager > > > ,
63
66
pub env_vars : EnvVariables ,
67
+ conda_executable : Arc < Mutex < Option < PathBuf > > > ,
64
68
}
65
69
66
70
impl Conda {
@@ -69,6 +73,7 @@ impl Conda {
69
73
environments : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
70
74
managers : Arc :: new ( Mutex :: new ( HashMap :: new ( ) ) ) ,
71
75
env_vars : EnvVariables :: from ( env) ,
76
+ conda_executable : Arc :: new ( Mutex :: new ( None ) ) ,
72
77
}
73
78
}
74
79
fn clear ( & self ) {
@@ -127,10 +132,19 @@ impl CondaLocator for Conda {
127
132
environments_txt = Some ( file) ;
128
133
}
129
134
135
+ let conda_exe = & self . conda_executable . lock ( ) . unwrap ( ) . clone ( ) ;
136
+ let envs_found = get_conda_environment_paths ( & self . env_vars , conda_exe) ;
137
+ let mut user_provided_env_found = None ;
138
+ if let Some ( conda_dir) = get_conda_dir_from_exe ( conda_exe) {
139
+ let conda_dir = norm_case ( conda_dir) ;
140
+ user_provided_env_found = Some ( envs_found. contains ( & conda_dir) ) ;
141
+ }
142
+
130
143
CondaTelemetryInfo {
131
144
can_spawn_conda,
132
145
conda_rcs,
133
146
env_dirs,
147
+ user_provided_env_found,
134
148
environments_txt,
135
149
environments_txt_exists,
136
150
environments_from_txt : get_conda_envs_from_environment_txt ( & self . env_vars ) ,
@@ -192,6 +206,12 @@ impl Locator for Conda {
192
206
fn get_name ( & self ) -> & ' static str {
193
207
"Conda" // Do not change this name, as this is used in telemetry.
194
208
}
209
+ fn configure ( & self , config : & pet_core:: Configuration ) {
210
+ if let Some ( ref conda_exe) = config. conda_executable {
211
+ let mut conda_executable = self . conda_executable . lock ( ) . unwrap ( ) ;
212
+ conda_executable. replace ( conda_exe. clone ( ) ) ;
213
+ }
214
+ }
195
215
fn supported_categories ( & self ) -> Vec < PythonEnvironmentKind > {
196
216
vec ! [ PythonEnvironmentKind :: Conda ]
197
217
}
@@ -262,9 +282,10 @@ impl Locator for Conda {
262
282
self . clear ( ) ;
263
283
264
284
let env_vars = self . env_vars . clone ( ) ;
285
+ let executable = self . conda_executable . lock ( ) . unwrap ( ) . clone ( ) ;
265
286
thread:: scope ( |s| {
266
287
// 1. Get a list of all know conda environments file paths
267
- let possible_conda_envs = get_conda_environment_paths ( & env_vars) ;
288
+ let possible_conda_envs = get_conda_environment_paths ( & env_vars, & executable ) ;
268
289
for path in possible_conda_envs {
269
290
s. spawn ( move || {
270
291
// 2. Get the details of the conda environment
0 commit comments