From eabe370e673b89415ae633c3774949ae790dd292 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Tue, 8 Oct 2024 11:55:00 -0700 Subject: [PATCH] Conda envs in envs dir cannot be conda install dir (#165) Cherry picking fixes into release branch. Fixes https://github.com/microsoft/vscode-python/issues/24247 Co-authored-by: Don Jayamanne --- crates/pet-conda/src/utils.rs | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/crates/pet-conda/src/utils.rs b/crates/pet-conda/src/utils.rs index b6fcdc94..2cc7276e 100644 --- a/crates/pet-conda/src/utils.rs +++ b/crates/pet-conda/src/utils.rs @@ -5,8 +5,29 @@ use std::path::{Path, PathBuf}; /// conda-meta must exist as this contains a mandatory `history` file. pub fn is_conda_install(path: &Path) -> bool { - (path.join("condabin").exists() || path.join("envs").exists()) + if (path.join("condabin").exists() || path.join("envs").exists()) && path.join("conda-meta").exists() + { + // For https://github.com/microsoft/vscode-python/issues/24247 + // Possible the env has a condabin or envs folder but its not the install directory. + // & in fact its just a regular conda env. + // Easy way is to check if the grand parent folder is a conda install directory. + if let Some(parent) = path.parent() { + if let Some(parent) = parent.parent() { + // If the grand parent is a conda install directory, + // then this is definitely not a conda install dir. + if (parent.join("condabin").exists() || parent.join("envs").exists()) + && parent.join("conda-meta").exists() + { + return false; + } + } + } + + return true; + } + + false } /// conda-meta must exist as this contains a mandatory `history` file.