Skip to content

Commit

Permalink
Ensure venv directories are never ignored (#167)
Browse files Browse the repository at this point in the history
Fixes #166
  • Loading branch information
DonJayamanne authored Oct 21, 2024
1 parent ed4edd6 commit ffcbf3f
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
17 changes: 15 additions & 2 deletions crates/pet/src/find.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ pub fn find_and_report_envs(
.insert("Path", start.elapsed());
});
// Step 3: Search in some global locations for virtual envs.
let environment_directories_search = environment_directories.clone();
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 {
for directory in environment_directories_search {
if let Ok(reader) = fs::read_dir(directory) {
possible_environments.append(
&mut reader
Expand Down Expand Up @@ -207,12 +208,14 @@ pub fn find_and_report_envs(
get_search_paths_from_env_variables(environment);
for workspace_folder in workspace_directories {
let global_env_search_paths = global_env_search_paths.clone();
let environment_directories = environment_directories.clone();
s.spawn(move || {
find_python_environments_in_workspace_folder_recursive(
&workspace_folder,
reporter,
locators,
&global_env_search_paths,
&environment_directories,
);
});
}
Expand Down Expand Up @@ -248,6 +251,7 @@ pub fn find_python_environments_in_workspace_folder_recursive(
reporter: &dyn Reporter,
locators: &Arc<Vec<Arc<dyn Locator>>>,
global_env_search_paths: &[PathBuf],
environment_directories: &[PathBuf],
) {
// When searching in a directory, give preference to some paths.
let paths_to_search_first = vec![
Expand Down Expand Up @@ -278,7 +282,16 @@ pub fn find_python_environments_in_workspace_folder_recursive(
.filter_map(Result::ok)
.filter(|d| d.file_type().is_ok_and(|f| f.is_dir()))
.map(|p| p.path())
.filter(should_search_for_environments_in_path)
.filter(|p| {
// If this directory is a sub directory or is in the environment_directories, then do not search in this directory.
if environment_directories.contains(p) {
return true;
}
if environment_directories.iter().any(|d| p.starts_with(d)) {
return true;
}
should_search_for_environments_in_path(p)
})
.filter(|p| !paths_to_search_first.contains(p))
{
find_python_environments(vec![folder], reporter, locators, true, &[]);
Expand Down
8 changes: 8 additions & 0 deletions crates/pet/src/jsonrpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,14 @@ pub fn handle_find(context: Arc<Context>, id: u32, params: Value) {
&reporter,
&context.locators,
&global_env_search_paths,
context
.configuration
.read()
.unwrap()
.clone()
.environment_directories
.as_deref()
.unwrap_or(&[]),
);
}

Expand Down

0 comments on commit ffcbf3f

Please sign in to comment.