Skip to content

Commit

Permalink
Conda envs in envs dir cannot be conda install dir (#165)
Browse files Browse the repository at this point in the history
Cherry picking fixes into release branch.
Fixes microsoft/vscode-python#24247

Co-authored-by: Don Jayamanne <[email protected]>
  • Loading branch information
karthiknadig and DonJayamanne authored Oct 8, 2024
1 parent f932cd8 commit eabe370
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion crates/pet-conda/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit eabe370

Please sign in to comment.