Skip to content

Commit d37098b

Browse files
committed
Identify conda env names
1 parent ac86ec2 commit d37098b

File tree

1 file changed

+13
-16
lines changed

1 file changed

+13
-16
lines changed

crates/pet-conda/src/environments.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,23 +37,20 @@ impl CondaEnvironment {
3737
) -> PythonEnvironment {
3838
#[allow(unused_assignments)]
3939
let mut name: Option<String> = None;
40-
if is_conda_install(&self.prefix) {
41-
name = Some("base".to_string());
42-
} else {
43-
name = self
44-
.prefix
45-
.file_name()
46-
.map(|name| name.to_str().unwrap_or_default().to_string());
47-
}
48-
// if the conda install folder is parent of the env folder, then we can use named activation.
49-
// E.g. conda env is = <conda install>/envs/<env name>
50-
// Then we can use `<conda install>/bin/conda activate -n <env name>`
51-
if let Some(conda_dir) = conda_dir {
52-
if !self.prefix.starts_with(conda_dir) {
53-
name = None;
54-
}
40+
41+
// We can name the conda envs only if we have a conda manager.
42+
if let Some(conda_manager) = &conda_manager {
43+
// If the conda manager for this environment is in the same folder as the conda environment,
44+
// Then this is a root conda environment.
45+
if conda_manager.executable.starts_with(&self.prefix) && is_conda_install(&self.prefix) && self.conda_dir.is_none(){
46+
name = Some("base".to_string());
47+
} else {
48+
name = self
49+
.prefix
50+
.file_name()
51+
.map(|name| name.to_str().unwrap_or_default().to_string());
5552
}
56-
// This is a root env.
53+
5754
let builder = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Conda))
5855
.executable(self.executable.clone())
5956
.version(self.version.clone())

0 commit comments

Comments
 (0)