@@ -14,14 +14,13 @@ use pet_core::{
1414 Locator , LocatorResult ,
1515} ;
1616use pet_python_utils:: env:: PythonEnv ;
17- use pet_virtualenv:: is_virtualenv;
1817use std:: {
1918 collections:: HashMap ,
2019 path:: { Path , PathBuf } ,
2120 sync:: { Arc , Mutex } ,
2221 thread,
2322} ;
24- use utils:: is_conda_install;
23+ use utils:: { is_conda_env , is_conda_install} ;
2524
2625mod conda_info;
2726pub mod conda_rc;
@@ -151,15 +150,29 @@ impl Locator for Conda {
151150 vec ! [ PythonEnvironmentCategory :: Conda ]
152151 }
153152 fn from ( & self , env : & PythonEnv ) -> Option < PythonEnvironment > {
154- // Assume we create a virtual env from a conda python install,
155- // Doing this is a big no no, but people do this.
156- // Then the exe in the virtual env bin will be a symlink to the homebrew python install.
157- // Hence the first part of the condition will be true, but the second part will be false.
158- if is_virtualenv ( env) {
159- return None ;
153+ // Possible we do not have the prefix, but this exe is in the bin directory and its a conda env or root conda install.
154+ let mut prefix = env. prefix . clone ( ) ;
155+ if prefix. is_none ( ) {
156+ if let Some ( parent_dir) = & env. executable . parent ( ) {
157+ if is_conda_env ( parent_dir) {
158+ // This is a conda env (most likely root conda env as the exe is in the same directory (generally on windows))
159+ prefix = Some ( parent_dir. to_path_buf ( ) ) ;
160+ } else if parent_dir. ends_with ( "bin" ) || parent_dir. ends_with ( "Scripts" ) {
161+ if let Some ( parent_dir) = parent_dir. parent ( ) {
162+ if is_conda_env ( parent_dir) {
163+ // This is a conda env
164+ prefix = Some ( parent_dir. to_path_buf ( ) ) ;
165+ }
166+ }
167+ }
168+ }
160169 }
161170
162- if let Some ( ref path) = env. prefix {
171+ if let Some ( ref path) = prefix {
172+ if !is_conda_env ( path) {
173+ return None ;
174+ }
175+
163176 let mut environments = self . environments . lock ( ) . unwrap ( ) ;
164177
165178 // Do we already have an env for this.
0 commit comments