@@ -2,6 +2,7 @@ use crate::args::{AnalyzeGraphArgs, ConfigArguments};
22use crate :: resolve:: resolve;
33use crate :: { ExitStatus , resolve_default_files} ;
44use anyhow:: Result ;
5+ use indexmap:: IndexSet ;
56use log:: { debug, warn} ;
67use path_absolutize:: CWD ;
78use ruff_db:: system:: { SystemPath , SystemPathBuf } ;
@@ -11,7 +12,7 @@ use ruff_linter::source_kind::SourceKind;
1112use ruff_linter:: { warn_user, warn_user_once} ;
1213use ruff_python_ast:: { PySourceType , SourceType } ;
1314use ruff_workspace:: resolver:: { ResolvedFile , match_exclusion, python_files_in_path} ;
14- use rustc_hash:: FxHashMap ;
15+ use rustc_hash:: { FxBuildHasher , FxHashMap } ;
1516use std:: io:: Write ;
1617use std:: path:: { Path , PathBuf } ;
1718use std:: sync:: { Arc , Mutex } ;
@@ -59,17 +60,13 @@ pub(crate) fn analyze_graph(
5960 } )
6061 . collect :: < FxHashMap < _ , _ > > ( ) ;
6162
62- // Create a database from the source roots, combining detected package roots with configured
63- // `src` paths.
64- let mut src_roots: Vec < SystemPathBuf > = package_roots
65- . values ( )
66- . filter_map ( |package| package. as_deref ( ) )
67- . filter_map ( |package| package. parent ( ) )
68- . map ( Path :: to_path_buf)
69- . filter_map ( |path| SystemPathBuf :: from_path_buf ( path) . ok ( ) )
70- . collect ( ) ;
71-
72- // Add configured `src` paths, filtering to only include existing directories.
63+ // Create a database from the source roots, combining configured `src` paths with detected
64+ // package roots. Configured paths are added first so they take precedence, and duplicates
65+ // are removed.
66+ let mut src_roots: IndexSet < SystemPathBuf , FxBuildHasher > = IndexSet :: default ( ) ;
67+
68+ // Add configured `src` paths first (for precedence), filtering to only include existing
69+ // directories.
7370 src_roots. extend (
7471 pyproject_config
7572 . settings
@@ -80,8 +77,17 @@ pub(crate) fn analyze_graph(
8077 . filter_map ( |path| SystemPathBuf :: from_path_buf ( path. clone ( ) ) . ok ( ) ) ,
8178 ) ;
8279
80+ // Add detected package roots.
81+ src_roots. extend (
82+ package_roots
83+ . values ( )
84+ . filter_map ( |package| package. as_deref ( ) )
85+ . filter_map ( |path| path. parent ( ) )
86+ . filter_map ( |path| SystemPathBuf :: from_path_buf ( path. to_path_buf ( ) ) . ok ( ) ) ,
87+ ) ;
88+
8389 let db = ModuleDb :: from_src_roots (
84- src_roots,
90+ src_roots. into_iter ( ) . collect ( ) ,
8591 pyproject_config
8692 . settings
8793 . analyze
0 commit comments