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
53 changes: 53 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/pet-conda/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ regex = "1.10.4"
pet-reporter = { path = "../pet-reporter" }
env_logger = "0.10.2"
yaml-rust2 = "0.8.1"
rayon = "1.11.0"

[features]
ci = []
19 changes: 6 additions & 13 deletions crates/pet-conda/src/environment_locations.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use crate::{
use log::trace;
use pet_fs::path::{expand_path, norm_case};
use pet_python_utils::platform_dirs::Platformdirs;
use rayon::prelude::*;
use std::{
env, fs,
path::{Path, PathBuf},
Expand Down Expand Up @@ -43,19 +44,11 @@ pub fn get_conda_environment_paths(
env_paths.dedup();
// For each env, check if we have a conda install directory in them and
// & then iterate through the list of envs in the envs directory.
// let env_paths = vec![];
let mut threads = vec![];
for path in env_paths.iter().filter(|f| f.exists()) {
let path = path.clone();
threads.push(thread::spawn(move || get_environments(&path)));
}

let mut result = vec![];
for thread in threads {
if let Ok(envs) = thread.join() {
result.extend(envs);
}
}
let mut result: Vec<PathBuf> = env_paths
.par_iter()
.filter(|f| f.exists())
.flat_map(|path| get_environments(path))
.collect();

result.sort();
result.dedup();
Expand Down
25 changes: 5 additions & 20 deletions crates/pet-conda/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use pet_core::{
Locator, LocatorKind,
};
use pet_fs::path::norm_case;
use rayon::prelude::*;
use serde::{Deserialize, Serialize};
use std::{
collections::HashMap,
Expand Down Expand Up @@ -371,24 +372,8 @@ fn get_conda_environments(
paths: &Vec<PathBuf>,
manager: &Option<CondaManager>,
) -> Vec<CondaEnvironment> {
let mut threads = vec![];
for path in paths {
let path = path.clone();
let mgr = manager.clone();
threads.push(thread::spawn(move || {
if let Some(env) = get_conda_environment_info(&path, &mgr) {
vec![env]
} else {
vec![]
}
}));
}

let mut envs: Vec<CondaEnvironment> = vec![];
for thread in threads {
if let Ok(mut result) = thread.join() {
envs.append(&mut result);
}
}
envs
paths
.par_iter()
.filter_map(|path| get_conda_environment_info(path, manager))
.collect()
}
1 change: 1 addition & 0 deletions crates/pet-homebrew/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,4 @@ lazy_static = "1.4.0"
pet-core = { path = "../pet-core" }
log = "0.4.21"
regex = "1.10.4"
rayon = "1.11.0"
43 changes: 19 additions & 24 deletions crates/pet-homebrew/src/sym_links.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use lazy_static::lazy_static;
use pet_fs::path::resolve_symlink;
use pet_python_utils::executable::find_executables;
use rayon::prelude::*;
use regex::Regex;
use std::{
fs,
Expand All @@ -30,32 +31,26 @@ pub fn get_known_symlinks(
// Go through all the exes in all of the above bin directories and verify we have a list of all of them.
// They too could be symlinks, e.g. we could have `/opt/homebrew/bin/python3` & also `/opt/homebrew/bin/python`
// And possible they are all symlnks to the same exe.
let threads = symlinks
.iter()
.map(|symlink| {
let symlink = symlink.clone();
let known_symlinks = symlinks.clone();
std::thread::spawn(move || {
if let Some(bin) = symlink.parent() {
let mut symlinks = vec![];
for possible_symlink in find_executables(bin) {
if let Some(symlink) = resolve_symlink(&possible_symlink) {
if known_symlinks.contains(&symlink) {
symlinks.push(possible_symlink);
}
let known_symlinks = symlinks.clone();
let other_symlinks: Vec<PathBuf> = symlinks
.par_iter()
.flat_map(|symlink| {
if let Some(bin) = symlink.parent() {
find_executables(bin)
.into_iter()
.filter(|possible_symlink| {
if let Some(resolved) = resolve_symlink(possible_symlink) {
known_symlinks.contains(&resolved)
} else {
false
}
}
symlinks
} else {
vec![]
}
})
})
.collect::<Vec<_>>()
} else {
vec![]
}
})
.collect::<Vec<_>>();
let other_symlinks = threads
.into_iter()
.flat_map(|t| t.join().unwrap())
.collect::<Vec<_>>();
.collect();
symlinks.extend(other_symlinks);

symlinks.sort();
Expand Down
Loading