Skip to content
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

Ensure venv directories are never ignored #167

Merged
merged 2 commits into from
Oct 21, 2024
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
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
Loading