diff --git a/crates/red_knot/src/main.rs b/crates/red_knot/src/main.rs index 812d994d3a152..0a7529a04546b 100644 --- a/crates/red_knot/src/main.rs +++ b/crates/red_knot/src/main.rs @@ -104,7 +104,7 @@ pub fn main() -> anyhow::Result<()> { extra_paths, workspace_root: workspace_metadata.root().to_path_buf(), custom_typeshed: custom_typeshed_dir, - site_packages: None, + site_packages: vec![], }, }; diff --git a/crates/red_knot/tests/file_watching.rs b/crates/red_knot/tests/file_watching.rs index c74ab4efdb287..dad017280ff2c 100644 --- a/crates/red_knot/tests/file_watching.rs +++ b/crates/red_knot/tests/file_watching.rs @@ -181,7 +181,7 @@ where extra_paths: vec![], workspace_root: workspace_path.to_path_buf(), custom_typeshed: None, - site_packages: None, + site_packages: vec![], }) } @@ -697,7 +697,7 @@ fn search_path() -> anyhow::Result<()> { extra_paths: vec![], workspace_root: workspace_path.to_path_buf(), custom_typeshed: None, - site_packages: Some(root_path.join("site_packages")), + site_packages: vec![root_path.join("site_packages")], } })?; @@ -734,7 +734,7 @@ fn add_search_path() -> anyhow::Result<()> { // Register site-packages as a search path. case.update_search_path_settings(|settings| SearchPathSettings { - site_packages: Some(site_packages.clone()), + site_packages: vec![site_packages.clone()], ..settings.clone() }); @@ -757,14 +757,14 @@ fn remove_search_path() -> anyhow::Result<()> { extra_paths: vec![], workspace_root: workspace_path.to_path_buf(), custom_typeshed: None, - site_packages: Some(root_path.join("site_packages")), + site_packages: vec![root_path.join("site_packages")], } })?; // Remove site packages from the search path settings. let site_packages = case.root_path().join("site_packages"); case.update_search_path_settings(|settings| SearchPathSettings { - site_packages: None, + site_packages: vec![], ..settings.clone() }); @@ -1175,7 +1175,7 @@ mod unix { extra_paths: vec![], workspace_root: workspace.to_path_buf(), custom_typeshed: None, - site_packages: Some(workspace.join(".venv/lib/python3.12/site-packages")), + site_packages: vec![workspace.join(".venv/lib/python3.12/site-packages")], }, )?; diff --git a/crates/red_knot_module_resolver/src/resolver.rs b/crates/red_knot_module_resolver/src/resolver.rs index a1c5f46a6bc8d..b66d706566abe 100644 --- a/crates/red_knot_module_resolver/src/resolver.rs +++ b/crates/red_knot_module_resolver/src/resolver.rs @@ -160,11 +160,18 @@ fn try_resolve_module_resolution_settings( SearchPath::vendored_stdlib() }); - if let Some(site_packages) = site_packages { - files.try_add_root(db.upcast(), site_packages, FileRootKind::LibrarySearchPath); + for site_packages_dir in site_packages { + files.try_add_root( + db.upcast(), + site_packages_dir, + FileRootKind::LibrarySearchPath, + ); - static_search_paths.push(SearchPath::site_packages(system, site_packages.clone())?); - }; + static_search_paths.push(SearchPath::site_packages( + system, + site_packages_dir.clone(), + )?); + } // TODO vendor typeshed's third-party stubs as well as the stdlib and fallback to them as a final step @@ -1180,7 +1187,7 @@ mod tests { extra_paths: vec![], workspace_root: src.clone(), custom_typeshed: Some(custom_typeshed.clone()), - site_packages: Some(site_packages.clone()), + site_packages: vec![site_packages], }; Program::new(&db, TargetVersion::Py38, search_paths); diff --git a/crates/red_knot_module_resolver/src/testing.rs b/crates/red_knot_module_resolver/src/testing.rs index 3a9e3e8d4f87e..51f4b30f640d2 100644 --- a/crates/red_knot_module_resolver/src/testing.rs +++ b/crates/red_knot_module_resolver/src/testing.rs @@ -12,6 +12,9 @@ pub(crate) struct TestCase { pub(crate) db: TestDb, pub(crate) src: SystemPathBuf, pub(crate) stdlib: T, + // Most test cases only ever need a single `site-packages` directory, + // so this is a single directory instead of a `Vec` of directories, + // like it is in `ruff_db::Program`. pub(crate) site_packages: SystemPathBuf, pub(crate) target_version: TargetVersion, } @@ -223,7 +226,7 @@ impl TestCaseBuilder { extra_paths: vec![], workspace_root: src.clone(), custom_typeshed: Some(typeshed.clone()), - site_packages: Some(site_packages.clone()), + site_packages: vec![site_packages.clone()], }, ); @@ -276,7 +279,7 @@ impl TestCaseBuilder { extra_paths: vec![], workspace_root: src.clone(), custom_typeshed: None, - site_packages: Some(site_packages.clone()), + site_packages: vec![site_packages.clone()], }, ); diff --git a/crates/red_knot_python_semantic/src/semantic_model.rs b/crates/red_knot_python_semantic/src/semantic_model.rs index aa5702170cd7a..d2c479cb47b70 100644 --- a/crates/red_knot_python_semantic/src/semantic_model.rs +++ b/crates/red_knot_python_semantic/src/semantic_model.rs @@ -179,7 +179,7 @@ mod tests { SearchPathSettings { extra_paths: vec![], workspace_root: SystemPathBuf::from("/src"), - site_packages: None, + site_packages: vec![], custom_typeshed: None, }, ); diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index f8cd746401e3e..c28fccc764a2d 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -1515,7 +1515,7 @@ mod tests { SearchPathSettings { extra_paths: Vec::new(), workspace_root: SystemPathBuf::from("/src"), - site_packages: None, + site_packages: vec![], custom_typeshed: None, }, ); @@ -1532,7 +1532,7 @@ mod tests { SearchPathSettings { extra_paths: Vec::new(), workspace_root: SystemPathBuf::from("/src"), - site_packages: None, + site_packages: vec![], custom_typeshed: Some(SystemPathBuf::from(typeshed)), }, ); diff --git a/crates/red_knot_workspace/src/lint.rs b/crates/red_knot_workspace/src/lint.rs index 27114bf251427..20eac583ab14d 100644 --- a/crates/red_knot_workspace/src/lint.rs +++ b/crates/red_knot_workspace/src/lint.rs @@ -326,7 +326,7 @@ mod tests { SearchPathSettings { extra_paths: Vec::new(), workspace_root, - site_packages: None, + site_packages: vec![], custom_typeshed: None, }, ); diff --git a/crates/red_knot_workspace/tests/check.rs b/crates/red_knot_workspace/tests/check.rs index a2d0f99207f02..ba92cc525bde8 100644 --- a/crates/red_knot_workspace/tests/check.rs +++ b/crates/red_knot_workspace/tests/check.rs @@ -14,7 +14,7 @@ fn setup_db(workspace_root: SystemPathBuf) -> anyhow::Result { extra_paths: vec![], workspace_root, custom_typeshed: None, - site_packages: None, + site_packages: vec![], }; let settings = ProgramSettings { target_version: TargetVersion::default(), diff --git a/crates/ruff_benchmark/benches/red_knot.rs b/crates/ruff_benchmark/benches/red_knot.rs index 079bd17200814..cc307d5c01b2d 100644 --- a/crates/ruff_benchmark/benches/red_knot.rs +++ b/crates/ruff_benchmark/benches/red_knot.rs @@ -74,7 +74,7 @@ fn setup_case() -> Case { search_paths: SearchPathSettings { extra_paths: vec![], workspace_root: workspace_root.to_path_buf(), - site_packages: None, + site_packages: vec![], custom_typeshed: None, }, }; diff --git a/crates/ruff_db/src/program.rs b/crates/ruff_db/src/program.rs index c5cdc30de64fd..78f3fc5a3b259 100644 --- a/crates/ruff_db/src/program.rs +++ b/crates/ruff_db/src/program.rs @@ -81,5 +81,5 @@ pub struct SearchPathSettings { pub custom_typeshed: Option, /// The path to the user's `site-packages` directory, where third-party packages from ``PyPI`` are installed. - pub site_packages: Option, + pub site_packages: Vec, }