@@ -138,13 +138,14 @@ pub fn find_and_report_envs(
138138 . insert ( "Path" , start. elapsed ( ) ) ;
139139 } ) ;
140140 // Step 3: Search in some global locations for virtual envs.
141+ let environment_directories_search = environment_directories. clone ( ) ;
141142 s. spawn ( || {
142143 let start = std:: time:: Instant :: now ( ) ;
143144 if search_global {
144145 let mut possible_environments = vec ! [ ] ;
145146
146147 // These are directories that contain environments, hence enumerate these directories.
147- for directory in environment_directories {
148+ for directory in environment_directories_search {
148149 if let Ok ( reader) = fs:: read_dir ( directory) {
149150 possible_environments. append (
150151 & mut reader
@@ -207,12 +208,14 @@ pub fn find_and_report_envs(
207208 get_search_paths_from_env_variables ( environment) ;
208209 for workspace_folder in workspace_directories {
209210 let global_env_search_paths = global_env_search_paths. clone ( ) ;
211+ let environment_directories = environment_directories. clone ( ) ;
210212 s. spawn ( move || {
211213 find_python_environments_in_workspace_folder_recursive (
212214 & workspace_folder,
213215 reporter,
214216 locators,
215217 & global_env_search_paths,
218+ & environment_directories,
216219 ) ;
217220 } ) ;
218221 }
@@ -248,6 +251,7 @@ pub fn find_python_environments_in_workspace_folder_recursive(
248251 reporter : & dyn Reporter ,
249252 locators : & Arc < Vec < Arc < dyn Locator > > > ,
250253 global_env_search_paths : & [ PathBuf ] ,
254+ environment_directories : & [ PathBuf ] ,
251255) {
252256 // When searching in a directory, give preference to some paths.
253257 let paths_to_search_first = vec ! [
@@ -278,7 +282,16 @@ pub fn find_python_environments_in_workspace_folder_recursive(
278282 . filter_map ( Result :: ok)
279283 . filter ( |d| d. file_type ( ) . is_ok_and ( |f| f. is_dir ( ) ) )
280284 . map ( |p| p. path ( ) )
281- . filter ( should_search_for_environments_in_path)
285+ . filter ( |p| {
286+ // If this directory is a sub directory or is in the environment_directories, then do not search in this directory.
287+ if environment_directories. contains ( p) {
288+ return true ;
289+ }
290+ if environment_directories. iter ( ) . any ( |d| p. starts_with ( d) ) {
291+ return true ;
292+ }
293+ should_search_for_environments_in_path ( p)
294+ } )
282295 . filter ( |p| !paths_to_search_first. contains ( p) )
283296 {
284297 find_python_environments ( vec ! [ folder] , reporter, locators, true , & [ ] ) ;
0 commit comments