From 5dc9f64c1b19aa5f8d727bde9e966605be10ff7c Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Fri, 4 Oct 2024 01:45:47 +1000 Subject: [PATCH] Expand the environments directories (#162) Fixes #161 --- crates/pet/src/find.rs | 17 ++++++++++++++++- crates/pet/tests/ci_homebrew_container.rs | 5 ++++- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/crates/pet/src/find.rs b/crates/pet/src/find.rs index 3b835281..89105235 100644 --- a/crates/pet/src/find.rs +++ b/crates/pet/src/find.rs @@ -141,13 +141,28 @@ pub fn find_and_report_envs( s.spawn(|| { let start = std::time::Instant::now(); if search_global { + let mut possible_environments = vec![]; + + // These are directories that contain environments, hence enumerate these directories. + for directory in environment_directories { + if let Ok(reader) = fs::read_dir(directory) { + possible_environments.append( + &mut reader + .filter_map(Result::ok) + .filter(|d| d.file_type().is_ok_and(|f| f.is_dir())) + .map(|p| p.path()) + .collect(), + ); + } + } + let search_paths: Vec = [ list_global_virtual_envs_paths( environment.get_env_var("WORKON_HOME".into()), environment.get_env_var("XDG_DATA_HOME".into()), environment.get_user_home(), ), - environment_directories, + possible_environments, ] .concat(); let global_env_search_paths: Vec = diff --git a/crates/pet/tests/ci_homebrew_container.rs b/crates/pet/tests/ci_homebrew_container.rs index 16d454d9..0275df39 100644 --- a/crates/pet/tests/ci_homebrew_container.rs +++ b/crates/pet/tests/ci_homebrew_container.rs @@ -50,7 +50,7 @@ fn verify_python_in_homebrew_contaner() { let python3_12 = PythonEnvironment { kind: Some(PythonEnvironmentKind::Homebrew), executable: Some(PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3")), - version: Some("3.12.6".to_string()), // This can change on CI, so we don't check it + version: Some("3.12.7".to_string()), // This can change on CI, so we don't check it symlinks: Some(vec![ PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3"), PathBuf::from("/home/linuxbrew/.linuxbrew/bin/python3.12"), @@ -103,6 +103,9 @@ fn verify_python_in_homebrew_contaner() { .filter(|p| { !p.to_string_lossy() .contains(&env.version.clone().unwrap_or_default()) + && !p + .to_string_lossy() + .contains(&python_env.version.clone().unwrap_or_default()) }) .collect::>(); assert_eq!(