Skip to content

Commit 8ce6f03

Browse files
committed
fix: improve conda environment name retrieval logic for external environments
1 parent 248575c commit 8ce6f03

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

crates/pet-conda/src/environments.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,10 +191,19 @@ fn get_conda_env_name(
191191
// if the conda install folder is parent of the env folder, then we can use named activation.
192192
// E.g. conda env is = <conda install>/envs/<env name>
193193
// Then we can use `<conda install>/bin/conda activate -n <env name>`
194-
if let Some(conda_dir) = conda_dir {
195-
if !prefix.starts_with(conda_dir) {
196-
name = get_conda_env_name_from_history_file(env_path, prefix);
197-
}
194+
//
195+
// Check the history file when:
196+
// 1. conda_dir is known but prefix is not under it (external environment)
197+
// 2. conda_dir is unknown (we need to check history to determine if it's name or path based)
198+
// This ensures path-based environments (created with --prefix) return None for name,
199+
// so activation uses the full path instead of incorrectly trying name-based activation.
200+
let should_check_history = match conda_dir {
201+
Some(dir) => !prefix.starts_with(dir),
202+
None => true,
203+
};
204+
205+
if should_check_history {
206+
name = get_conda_env_name_from_history_file(env_path, prefix);
198207
}
199208

200209
name

0 commit comments

Comments
 (0)