Skip to content

Commit 8b8e13c

Browse files
committed
Fix tests
1 parent d37098b commit 8b8e13c

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

crates/pet-conda/src/environments.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,25 +30,25 @@ impl CondaEnvironment {
3030
get_conda_environment_info(path, manager)
3131
}
3232

33-
pub fn to_python_environment(
34-
&self,
35-
conda_dir: Option<PathBuf>,
36-
conda_manager: Option<EnvManager>,
37-
) -> PythonEnvironment {
33+
pub fn to_python_environment(&self, conda_manager: Option<EnvManager>) -> PythonEnvironment {
3834
#[allow(unused_assignments)]
3935
let mut name: Option<String> = None;
4036

4137
// We can name the conda envs only if we have a conda manager.
4238
if let Some(conda_manager) = &conda_manager {
4339
// If the conda manager for this environment is in the same folder as the conda environment,
4440
// 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(){
41+
if conda_manager.executable.starts_with(&self.prefix)
42+
&& is_conda_install(&self.prefix)
43+
&& !self.conda_dir.is_none()
44+
{
4645
name = Some("base".to_string());
4746
} else {
4847
name = self
4948
.prefix
5049
.file_name()
5150
.map(|name| name.to_str().unwrap_or_default().to_string());
51+
}
5252
}
5353

5454
let builder = PythonEnvironmentBuilder::new(Some(PythonEnvironmentKind::Conda))

crates/pet-conda/src/lib.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -174,8 +174,7 @@ impl CondaLocator for Conda {
174174
if environments.contains_key(&conda_env.prefix) {
175175
continue;
176176
}
177-
let env = conda_env
178-
.to_python_environment(Some(conda_dir.clone()), Some(manager.to_manager()));
177+
let env = conda_env.to_python_environment(Some(manager.to_manager()));
179178
environments.insert(conda_env.prefix.clone(), env.clone());
180179
reporter.report_manager(&manager.to_manager());
181180
reporter.report_environment(&env);
@@ -248,18 +247,15 @@ impl Locator for Conda {
248247
if let Some(env) = get_conda_environment_info(path, &None) {
249248
if let Some(conda_dir) = &env.conda_dir {
250249
if let Some(manager) = self.get_manager(conda_dir) {
251-
let env = env.to_python_environment(
252-
Some(conda_dir.clone()),
253-
Some(manager.to_manager()),
254-
);
250+
let env = env.to_python_environment(Some(manager.to_manager()));
255251
environments.insert(path.clone(), env.clone());
256252
return Some(env);
257253
} else {
258254
// We will still return the conda env even though we do not have the manager.
259255
// This might seem incorrect, however the tool is about discovering environments.
260256
// The client can activate this env either using another conda manager or using the activation scripts
261257
error!("Unable to find Conda Manager for env (even though we have a conda_dir): {:?}", env);
262-
let env = env.to_python_environment(Some(conda_dir.clone()), None);
258+
let env = env.to_python_environment(None);
263259
environments.insert(path.clone(), env.clone());
264260
return Some(env);
265261
}
@@ -268,7 +264,7 @@ impl Locator for Conda {
268264
// This might seem incorrect, however the tool is about discovering environments.
269265
// The client can activate this env either using another conda manager or using the activation scripts
270266
error!("Unable to find Conda Manager for env: {:?}", env);
271-
let env = env.to_python_environment(None, None);
267+
let env = env.to_python_environment(None);
272268
environments.insert(path.clone(), env.clone());
273269
return Some(env);
274270
}
@@ -301,7 +297,7 @@ impl Locator for Conda {
301297
// The client can activate this env either using another conda manager or using the activation scripts
302298
error!("Unable to find Conda Manager for the Conda env: {:?}", env);
303299
let prefix = env.prefix.clone();
304-
let env = env.to_python_environment(None, None);
300+
let env = env.to_python_environment(None);
305301
let mut environments = self.environments.lock().unwrap();
306302
environments.insert(prefix, env.clone());
307303
reporter.report_environment(&env);
@@ -340,7 +336,6 @@ impl Locator for Conda {
340336
// 5. Report this env.
341337
if let Some(manager) = manager {
342338
let env = env.to_python_environment(
343-
manager.conda_dir.clone(),
344339
Some(manager.to_manager()),
345340
);
346341
let mut environments = self.environments.lock().unwrap();
@@ -352,7 +347,7 @@ impl Locator for Conda {
352347
// This might seem incorrect, however the tool is about discovering environments.
353348
// The client can activate this env either using another conda manager or using the activation scripts
354349
error!("Unable to find Conda Manager for Conda env (even though we have a conda_dir {:?}): Env Details = {:?}", conda_dir, env);
355-
let env = env.to_python_environment(Some(conda_dir.clone()), None);
350+
let env = env.to_python_environment(None);
356351
let mut environments = self.environments.lock().unwrap();
357352
environments.insert(prefix.clone(), env.clone());
358353
reporter.report_environment(&env);

crates/pet-conda/tests/lib_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ fn find_conda_env_without_manager() {
3232
assert_eq!(env.executable, path.join("bin").join("python").into());
3333
assert_eq!(env.version, "3.12.2".to_string().into());
3434
assert_eq!(env.manager, None);
35-
assert_eq!(env.name, "env_python_3".to_string().into());
35+
assert_eq!(env.name, None);
3636
}
3737

3838
#[cfg(unix)]
@@ -90,5 +90,5 @@ fn find_conda_env_without_manager_but_detect_manager_from_history() {
9090
env.manager.clone().unwrap().version,
9191
"23.1.0".to_string().into()
9292
);
93-
assert_eq!(env.name, None);
93+
assert_eq!(env.name, "env_python_3".to_string().into());
9494
}

0 commit comments

Comments
 (0)