Skip to content

Fix env duplication on merged-usr systems #200

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions crates/pet-env-var-path/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Licensed under the MIT License.

use pet_core::os_environment::Environment;
use std::collections::HashSet;
use std::fs;
use std::path::PathBuf;

pub fn get_search_paths_from_env_variables(environment: &dyn Environment) -> Vec<PathBuf> {
Expand All @@ -16,10 +18,12 @@ pub fn get_search_paths_from_env_variables(environment: &dyn Environment) -> Vec

environment
.get_know_global_search_locations()
.clone()
.into_iter()
.map(|p| fs::canonicalize(&p).unwrap_or(p))
.collect::<HashSet<PathBuf>>()
.into_iter()
.filter(|p| !p.starts_with(apps_path.clone()))
.collect::<Vec<PathBuf>>()
.collect()
} else {
Vec::new()
}
Expand Down
17 changes: 12 additions & 5 deletions crates/pet-linux-global-python/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Licensed under the MIT License.

use std::{
collections::HashMap,
collections::{HashMap, HashSet},
fs,
path::{Path, PathBuf},
sync::{Arc, Mutex},
Expand Down Expand Up @@ -38,10 +38,17 @@ impl LinuxGlobalPython {
return;
}
// Look through the /bin, /usr/bin, /usr/local/bin directories
let bin_dirs: HashSet<_> = [
Path::new("/bin"),
Path::new("/usr/bin"),
Path::new("/usr/local/bin"),
]
.map(|p| fs::canonicalize(p).unwrap_or(p.to_path_buf()))
.into();
thread::scope(|s| {
for bin in ["/bin", "/usr/bin", "/usr/local/bin"] {
for bin in bin_dirs {
s.spawn(move || {
find_and_report_global_pythons_in(bin, reporter, &self.reported_executables);
find_and_report_global_pythons_in(&bin, reporter, &self.reported_executables);
});
}
});
Expand Down Expand Up @@ -103,11 +110,11 @@ impl Locator for LinuxGlobalPython {
}

fn find_and_report_global_pythons_in(
bin: &str,
bin: &Path,
reporter: Option<&dyn Reporter>,
reported_executables: &Arc<Mutex<HashMap<PathBuf, PythonEnvironment>>>,
) {
let python_executables = find_executables(Path::new(bin));
let python_executables = find_executables(bin);

for exe in python_executables.clone().iter() {
if reported_executables.lock().unwrap().contains_key(exe) {
Expand Down
37 changes: 4 additions & 33 deletions crates/pet/tests/ci_jupyter_container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,30 +70,16 @@ fn verify_python_in_jupyter_contaner() {
}),
..Default::default()
};
let codespace_python = PythonEnvironment {
kind: Some(PythonEnvironmentKind::GlobalPaths),
executable: Some(PathBuf::from("/home/codespace/.python/current/bin/python")),
prefix: Some(PathBuf::from("/usr/local/python/3.10.13")),
version: Some("3.10.13.final.0".to_string()),
arch: Some(Architecture::X64),
symlinks: Some(vec![
PathBuf::from("/home/codespace/.python/current/bin/python"),
PathBuf::from("/home/codespace/.python/current/bin/python3"),
PathBuf::from("/home/codespace/.python/current/bin/python3.10"),
]),
manager: None,
..Default::default()
};
let current_python = PythonEnvironment {
kind: Some(PythonEnvironmentKind::GlobalPaths),
executable: Some(PathBuf::from("/usr/local/python/current/bin/python")),
executable: Some(PathBuf::from("/usr/local/python/3.10.13/bin/python")),
prefix: Some(PathBuf::from("/usr/local/python/3.10.13")),
version: Some("3.10.13.final.0".to_string()),
arch: Some(Architecture::X64),
symlinks: Some(vec![
PathBuf::from("/usr/local/python/current/bin/python"),
PathBuf::from("/usr/local/python/current/bin/python3"),
PathBuf::from("/usr/local/python/current/bin/python3.10"),
PathBuf::from("/usr/local/python/3.10.13/bin/python"),
PathBuf::from("/usr/local/python/3.10.13/bin/python3"),
PathBuf::from("/usr/local/python/3.10.13/bin/python3.10"),
]),
manager: None,
..Default::default()
Expand All @@ -111,26 +97,11 @@ fn verify_python_in_jupyter_contaner() {
manager: None,
..Default::default()
};
let bin_python = PythonEnvironment {
kind: Some(PythonEnvironmentKind::LinuxGlobal),
executable: Some(PathBuf::from("/bin/python3")),
prefix: Some(PathBuf::from("/usr")),
version: Some("3.8.10.final.0".to_string()),
arch: Some(Architecture::X64),
symlinks: Some(vec![
PathBuf::from("/bin/python3"),
PathBuf::from("/bin/python3.8"),
]),
manager: None,
..Default::default()
};

for env in [
conda,
codespace_python,
current_python,
usr_bin_python,
bin_python,
]
.iter()
{
Expand Down