Skip to content

Commit be7ddba

Browse files
committed
Updates
1 parent 54d4ffe commit be7ddba

File tree

2 files changed

+46
-16
lines changed

2 files changed

+46
-16
lines changed

crates/pet-conda/src/lib.rs

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use environment_locations::{
88
get_environments,
99
};
1010
use environments::{get_conda_environment_info, CondaEnvironment};
11-
use log::error;
11+
use log::{error, trace};
1212
use manager::CondaManager;
1313
use pet_core::{
1414
env::PythonEnv,
@@ -155,8 +155,11 @@ impl CondaLocator for Conda {
155155
if !is_conda_install(conda_dir) {
156156
return;
157157
}
158+
trace!("2. Find and report conda environments in {:?}", conda_dir);
158159
if let Some(manager) = CondaManager::from(conda_dir) {
159160
if let Some(conda_dir) = manager.conda_dir.clone() {
161+
trace!("2. Found conda manager in {:?} {:?}", manager, conda_dir);
162+
trace!("2. Find and report conda environments in {:?}", conda_dir);
160163
// Keep track to search again later.
161164
// Possible we'll find environments in other directories created using this manager
162165
let mut managers = self.managers.lock().unwrap();
@@ -169,6 +172,12 @@ impl CondaLocator for Conda {
169172
for conda_env in
170173
get_conda_environments(&get_environments(&conda_dir), &manager.clone().into())
171174
{
175+
trace!(
176+
"2. Found conda environment {:?} in {:?} for {:?}",
177+
conda_env,
178+
conda_dir,
179+
manager
180+
);
172181
// If reported earlier, no point processing this again.
173182
let mut environments = self.environments.lock().unwrap();
174183
if environments.contains_key(&conda_env.prefix) {
@@ -247,7 +256,14 @@ impl Locator for Conda {
247256
}
248257
if let Some(env) = get_conda_environment_info(path, &None) {
249258
if let Some(conda_dir) = &env.conda_dir {
259+
trace!("4. Found conda env {:?} in {:?}", env, path);
250260
if let Some(manager) = self.get_manager(conda_dir) {
261+
trace!(
262+
"4. Found conda manager {:?} for env {:?} in {:?}",
263+
manager,
264+
env,
265+
path
266+
);
251267
let env = env.to_python_environment(
252268
Some(conda_dir.clone()),
253269
Some(manager.to_manager()),
@@ -329,8 +345,10 @@ impl Locator for Conda {
329345
drop(managers);
330346

331347
if manager.is_none() {
348+
trace!("3.1 Finding conda manager for {:?} for path: {:?}", env, conda_dir);
332349
// 4.1 Build the manager from the conda dir if we do not have it.
333350
if let Some(conda_manager) = CondaManager::from(conda_dir) {
351+
trace!("3.1 Found conda manager {:?} for {:?} for path: {:?}", conda_manager,env, conda_dir);
334352
let mut managers = self.managers.lock().unwrap();
335353
managers.insert(conda_dir.to_path_buf().clone(), conda_manager.clone());
336354
manager = Some(conda_manager);

crates/pet-conda/src/manager.rs

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,13 @@
22
// Licensed under the MIT License.
33

44
use crate::{
5-
conda_info::CondaInfo, env_variables::EnvVariables,
6-
environments::get_conda_installation_used_to_create_conda_env, package::CondaPackageInfo,
7-
utils::is_conda_env,
5+
conda_info::CondaInfo,
6+
env_variables::EnvVariables,
7+
environments::get_conda_installation_used_to_create_conda_env,
8+
package::CondaPackageInfo,
9+
utils::{is_conda_env, is_conda_install},
810
};
11+
use log::trace;
912
use pet_core::{manager::EnvManager, manager::EnvManagerType};
1013
use std::{
1114
env,
@@ -75,24 +78,33 @@ impl CondaManager {
7578
}
7679
}
7780
pub fn from(path: &Path) -> Option<CondaManager> {
81+
trace!("1. Finding conda manager for path: {:?}", path);
7882
if !is_conda_env(path) {
7983
return None;
8084
}
85+
86+
// If this environment is in a folder named `envs`, then the parent directory of `envs` is the root conda install folder.
87+
if let Some(parent) = path.ancestors().nth(2) {
88+
trace!("1. Finding conda manager from parent path: {:?}", parent);
89+
if is_conda_install(parent) {
90+
if let Some(manager) = get_conda_manager(parent) {
91+
trace!("1. Found conda manager from parent path: {:?}", parent);
92+
return Some(manager);
93+
}
94+
}
95+
}
96+
8197
if let Some(manager) = get_conda_manager(path) {
98+
trace!("1. Found conda manager from path: {:?}", path);
8299
Some(manager)
83100
} else {
84-
// Possible this is a conda environment in the `envs` folder
85-
let path = path.parent()?.parent()?;
86-
if let Some(manager) = get_conda_manager(path) {
87-
Some(manager)
88-
} else {
89-
// Possible this is a conda environment in some other location
90-
// Such as global env folders location configured via condarc file
91-
// Or a conda env created using `-p` flag.
92-
// Get the conda install folder from the history file.
93-
let conda_install_folder = get_conda_installation_used_to_create_conda_env(path)?;
94-
get_conda_manager(&conda_install_folder)
95-
}
101+
// Possible this is a conda environment in some other location
102+
// Such as global env folders location configured via condarc file
103+
// Or a conda env created using `-p` flag.
104+
// Get the conda install folder from the history file.
105+
trace!("1. Find conda manager from install path: {:?}", path);
106+
let conda_install_folder = get_conda_installation_used_to_create_conda_env(path)?;
107+
get_conda_manager(&conda_install_folder)
96108
}
97109
}
98110
pub fn from_info(executable: &Path, info: &CondaInfo) -> Option<CondaManager> {

0 commit comments

Comments
 (0)