Skip to content

Commit

Permalink
[red-knot] Rename workspace_root variables in the module resolver t…
Browse files Browse the repository at this point in the history
…o `src_root` (#12697)

Fixes #12337
  • Loading branch information
AlexWaygood authored Aug 5, 2024
1 parent 7ee7c68 commit 5499821
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ pub fn main() -> anyhow::Result<()> {
target_version: target_version.into(),
search_paths: SearchPathSettings {
extra_paths,
workspace_root: workspace_metadata.root().to_path_buf(),
src_root: workspace_metadata.root().to_path_buf(),
custom_typeshed: custom_typeshed_dir,
site_packages: vec![],
},
Expand Down
8 changes: 4 additions & 4 deletions crates/red_knot/tests/file_watching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ where
{
setup_with_search_paths(setup_files, |_root, workspace_path| SearchPathSettings {
extra_paths: vec![],
workspace_root: workspace_path.to_path_buf(),
src_root: workspace_path.to_path_buf(),
custom_typeshed: None,
site_packages: vec![],
})
Expand Down Expand Up @@ -695,7 +695,7 @@ fn search_path() -> anyhow::Result<()> {
setup_with_search_paths([("bar.py", "import sub.a")], |root_path, workspace_path| {
SearchPathSettings {
extra_paths: vec![],
workspace_root: workspace_path.to_path_buf(),
src_root: workspace_path.to_path_buf(),
custom_typeshed: None,
site_packages: vec![root_path.join("site_packages")],
}
Expand Down Expand Up @@ -755,7 +755,7 @@ fn remove_search_path() -> anyhow::Result<()> {
setup_with_search_paths([("bar.py", "import sub.a")], |root_path, workspace_path| {
SearchPathSettings {
extra_paths: vec![],
workspace_root: workspace_path.to_path_buf(),
src_root: workspace_path.to_path_buf(),
custom_typeshed: None,
site_packages: vec![root_path.join("site_packages")],
}
Expand Down Expand Up @@ -1173,7 +1173,7 @@ mod unix {
},
|_root, workspace| SearchPathSettings {
extra_paths: vec![],
workspace_root: workspace.to_path_buf(),
src_root: workspace.to_path_buf(),
custom_typeshed: None,
site_packages: vec![workspace.join(".venv/lib/python3.12/site-packages")],
},
Expand Down
10 changes: 5 additions & 5 deletions crates/red_knot_module_resolver/src/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ fn try_resolve_module_resolution_settings(

let SearchPathSettings {
extra_paths,
workspace_root,
src_root,
custom_typeshed,
site_packages,
} = program.search_paths(db.upcast());
Expand All @@ -146,7 +146,7 @@ fn try_resolve_module_resolution_settings(
static_search_paths.push(SearchPath::extra(system, path.clone())?);
}

static_search_paths.push(SearchPath::first_party(system, workspace_root.clone())?);
static_search_paths.push(SearchPath::first_party(system, src_root.clone())?);

static_search_paths.push(if let Some(custom_typeshed) = custom_typeshed.as_ref() {
files.try_add_root(
Expand Down Expand Up @@ -459,7 +459,7 @@ fn resolve_name(db: &dyn Db, name: &ModuleName) -> Option<(SearchPath, File, Mod
for search_path in resolver_settings.search_paths(db) {
// When a builtin module is imported, standard module resolution is bypassed:
// the module name always resolves to the stdlib module,
// even if there's a module of the same name in the workspace root
// even if there's a module of the same name in the first-party root
// (which would normally result in the stdlib module being overridden).
if is_builtin_module && !search_path.is_standard_library() {
continue;
Expand Down Expand Up @@ -1160,7 +1160,7 @@ mod tests {

let search_paths = SearchPathSettings {
extra_paths: vec![],
workspace_root: src.clone(),
src_root: src.clone(),
custom_typeshed: Some(custom_typeshed.clone()),
site_packages: vec![site_packages],
};
Expand Down Expand Up @@ -1664,7 +1664,7 @@ not_a_directory
TargetVersion::default(),
SearchPathSettings {
extra_paths: vec![],
workspace_root: SystemPathBuf::from("/src"),
src_root: SystemPathBuf::from("/src"),
custom_typeshed: None,
site_packages: vec![venv_site_packages, system_site_packages],
},
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_module_resolver/src/testing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl TestCaseBuilder<MockedTypeshed> {
target_version,
SearchPathSettings {
extra_paths: vec![],
workspace_root: src.clone(),
src_root: src.clone(),
custom_typeshed: Some(typeshed.clone()),
site_packages: vec![site_packages.clone()],
},
Expand Down Expand Up @@ -277,7 +277,7 @@ impl TestCaseBuilder<VendoredTypeshed> {
target_version,
SearchPathSettings {
extra_paths: vec![],
workspace_root: src.clone(),
src_root: src.clone(),
custom_typeshed: None,
site_packages: vec![site_packages.clone()],
},
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/src/semantic_model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ mod tests {
TargetVersion::Py38,
SearchPathSettings {
extra_paths: vec![],
workspace_root: SystemPathBuf::from("/src"),
src_root: SystemPathBuf::from("/src"),
site_packages: vec![],
custom_typeshed: None,
},
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1516,7 +1516,7 @@ mod tests {
TargetVersion::Py38,
SearchPathSettings {
extra_paths: Vec::new(),
workspace_root: SystemPathBuf::from("/src"),
src_root: SystemPathBuf::from("/src"),
site_packages: vec![],
custom_typeshed: None,
},
Expand All @@ -1533,7 +1533,7 @@ mod tests {
TargetVersion::Py38,
SearchPathSettings {
extra_paths: Vec::new(),
workspace_root: SystemPathBuf::from("/src"),
src_root: SystemPathBuf::from("/src"),
site_packages: vec![],
custom_typeshed: Some(SystemPathBuf::from(typeshed)),
},
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_workspace/src/lint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,15 @@ mod tests {
setup_db_with_root(SystemPathBuf::from("/src"))
}

fn setup_db_with_root(workspace_root: SystemPathBuf) -> TestDb {
fn setup_db_with_root(src_root: SystemPathBuf) -> TestDb {
let db = TestDb::new();

Program::new(
&db,
TargetVersion::Py38,
SearchPathSettings {
extra_paths: Vec::new(),
workspace_root,
src_root,
site_packages: vec![],
custom_typeshed: None,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_workspace/tests/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ fn setup_db(workspace_root: SystemPathBuf) -> anyhow::Result<RootDatabase> {
let workspace = WorkspaceMetadata::from_path(&workspace_root, &system)?;
let search_paths = SearchPathSettings {
extra_paths: vec![],
workspace_root,
src_root: workspace_root,
custom_typeshed: None,
site_packages: vec![],
};
Expand Down
6 changes: 3 additions & 3 deletions crates/ruff_benchmark/benches/red_knot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ fn setup_case() -> Case {
])
.unwrap();

let workspace_root = SystemPath::new("/src");
let metadata = WorkspaceMetadata::from_path(workspace_root, &system).unwrap();
let src_root = SystemPath::new("/src");
let metadata = WorkspaceMetadata::from_path(src_root, &system).unwrap();
let settings = ProgramSettings {
target_version: TargetVersion::Py312,
search_paths: SearchPathSettings {
extra_paths: vec![],
workspace_root: workspace_root.to_path_buf(),
src_root: src_root.to_path_buf(),
site_packages: vec![],
custom_typeshed: None,
},
Expand Down
2 changes: 1 addition & 1 deletion crates/ruff_db/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub struct SearchPathSettings {
pub extra_paths: Vec<SystemPathBuf>,

/// The root of the workspace, used for finding first-party modules.
pub workspace_root: SystemPathBuf,
pub src_root: SystemPathBuf,

/// Optional path to a "custom typeshed" directory on disk for us to use for standard-library types.
/// If this is not provided, we will fallback to our vendored typeshed stubs for the stdlib,
Expand Down

0 comments on commit 5499821

Please sign in to comment.