Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 4 additions & 10 deletions crates/pet-conda/src/environments.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ impl CondaEnvironment {
get_conda_environment_info(path, manager)
}

pub fn to_python_environment(
&self,
conda_dir: Option<PathBuf>,
conda_manager: Option<EnvManager>,
) -> PythonEnvironment {
pub fn to_python_environment(&self, conda_manager: Option<EnvManager>) -> PythonEnvironment {
#[allow(unused_assignments)]
let mut name: Option<String> = None;
if is_conda_install(&self.prefix) {
Expand All @@ -48,7 +44,7 @@ impl CondaEnvironment {
// if the conda install folder is parent of the env folder, then we can use named activation.
// E.g. conda env is = <conda install>/envs/<env name>
// Then we can use `<conda install>/bin/conda activate -n <env name>`
if let Some(conda_dir) = conda_dir {
if let Some(conda_dir) = &self.conda_dir {
if !self.prefix.starts_with(conda_dir) {
name = None;
}
Expand Down Expand Up @@ -76,10 +72,8 @@ pub fn get_conda_environment_info(
return None;
}
// If we know the conda install folder, then we can use it.
let mut conda_install_folder = manager
.clone()
.and_then(|m| m.conda_dir)
.or_else(|| get_conda_installation_used_to_create_conda_env(env_path));
let mut conda_install_folder = get_conda_installation_used_to_create_conda_env(env_path)
.or_else(|| manager.clone().and_then(|m| m.conda_dir));

if let Some(conda_dir) = &conda_install_folder {
if conda_dir.exists() {
Expand Down
25 changes: 14 additions & 11 deletions crates/pet-conda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,15 @@ impl CondaLocator for Conda {
if environments.contains_key(&conda_env.prefix) {
continue;
}
let env = conda_env
.to_python_environment(Some(conda_dir.clone()), Some(manager.to_manager()));

// Get the right manager for this conda env.
// Possible the manager is different from the one we got from the conda_dir.
let manager = conda_env
.clone()
.conda_dir
.and_then(|p| CondaManager::from(&p))
.unwrap_or(manager.clone());
let env = conda_env.to_python_environment(Some(manager.to_manager()));
environments.insert(conda_env.prefix.clone(), env.clone());
reporter.report_manager(&manager.to_manager());
reporter.report_environment(&env);
Expand Down Expand Up @@ -248,18 +255,15 @@ impl Locator for Conda {
if let Some(env) = get_conda_environment_info(path, &None) {
if let Some(conda_dir) = &env.conda_dir {
if let Some(manager) = self.get_manager(conda_dir) {
let env = env.to_python_environment(
Some(conda_dir.clone()),
Some(manager.to_manager()),
);
let env = env.to_python_environment(Some(manager.to_manager()));
environments.insert(path.clone(), env.clone());
return Some(env);
} else {
// We will still return the conda env even though we do not have the manager.
// This might seem incorrect, however the tool is about discovering environments.
// The client can activate this env either using another conda manager or using the activation scripts
error!("Unable to find Conda Manager for env (even though we have a conda_dir): {:?}", env);
let env = env.to_python_environment(Some(conda_dir.clone()), None);
let env = env.to_python_environment(None);
environments.insert(path.clone(), env.clone());
return Some(env);
}
Expand All @@ -268,7 +272,7 @@ impl Locator for Conda {
// This might seem incorrect, however the tool is about discovering environments.
// The client can activate this env either using another conda manager or using the activation scripts
error!("Unable to find Conda Manager for env: {:?}", env);
let env = env.to_python_environment(None, None);
let env = env.to_python_environment(None);
environments.insert(path.clone(), env.clone());
return Some(env);
}
Expand Down Expand Up @@ -301,7 +305,7 @@ impl Locator for Conda {
// The client can activate this env either using another conda manager or using the activation scripts
error!("Unable to find Conda Manager for the Conda env: {:?}", env);
let prefix = env.prefix.clone();
let env = env.to_python_environment(None, None);
let env = env.to_python_environment(None);
let mut environments = self.environments.lock().unwrap();
environments.insert(prefix, env.clone());
reporter.report_environment(&env);
Expand Down Expand Up @@ -340,7 +344,6 @@ impl Locator for Conda {
// 5. Report this env.
if let Some(manager) = manager {
let env = env.to_python_environment(
manager.conda_dir.clone(),
Some(manager.to_manager()),
);
let mut environments = self.environments.lock().unwrap();
Expand All @@ -352,7 +355,7 @@ impl Locator for Conda {
// This might seem incorrect, however the tool is about discovering environments.
// The client can activate this env either using another conda manager or using the activation scripts
error!("Unable to find Conda Manager for Conda env (even though we have a conda_dir {:?}): Env Details = {:?}", conda_dir, env);
let env = env.to_python_environment(Some(conda_dir.clone()), None);
let env = env.to_python_environment(None);
let mut environments = self.environments.lock().unwrap();
environments.insert(prefix.clone(), env.clone());
reporter.report_environment(&env);
Expand Down
Loading