Skip to content

Commit 729ffe6

Browse files
committed
Fixes
1 parent be7ddba commit 729ffe6

File tree

2 files changed

+28
-11
lines changed

2 files changed

+28
-11
lines changed

crates/pet-conda/src/environments.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ pub fn get_conda_environment_info(
8484
if let Some(conda_dir) = &conda_install_folder {
8585
if conda_dir.exists() {
8686
trace!(
87-
"Conda install folder {}, found, & will not be used for the Conda Env: {}",
87+
"Conda install folder {}, found, & will be used for the Conda Env: {}",
8888
env_path.display(),
8989
conda_dir.display()
9090
);

crates/pet-conda/src/manager.rs

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -94,17 +94,34 @@ impl CondaManager {
9494
}
9595
}
9696

97-
if let Some(manager) = get_conda_manager(path) {
98-
trace!("1. Found conda manager from path: {:?}", path);
99-
Some(manager)
100-
} else {
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)?;
97+
// Possible this is a conda environment in some other location
98+
// Such as global env folders location configured via condarc file
99+
// Or a conda env created using `-p` flag.
100+
// Get the conda install folder from the history file.
101+
// Or its in a location such as `~/.conda/envs` or `~/miniconda3/envs` where the conda install folder is not a parent of this path.
102+
trace!("1. Find conda manager from install path: {:?}", path);
103+
if let Some(conda_install_folder) = get_conda_installation_used_to_create_conda_env(path) {
107104
get_conda_manager(&conda_install_folder)
105+
} else {
106+
// If this is a conda env and the parent is `.conda/envs`, then this is definitely NOT a root conda install folder.
107+
// Hence never use conda installs from these env paths.
108+
if let Some(parent) = path.parent() {
109+
if parent.ends_with(".conda/envs") {
110+
trace!(
111+
"Parent path ends with .conda/envs, not a root conda install folder: {:?}",
112+
parent
113+
);
114+
return None;
115+
}
116+
}
117+
118+
if let Some(manager) = get_conda_manager(path) {
119+
trace!("1. Found conda manager from path: {:?}", path);
120+
Some(manager)
121+
} else {
122+
trace!("No conda manager found for path: {:?}", path);
123+
None
124+
}
108125
}
109126
}
110127
pub fn from_info(executable: &Path, info: &CondaInfo) -> Option<CondaManager> {

0 commit comments

Comments
 (0)