Skip to content

Commit 5499821

Browse files
authored
[red-knot] Rename workspace_root variables in the module resolver to src_root (#12697)
Fixes #12337
1 parent 7ee7c68 commit 5499821

10 files changed

Lines changed: 22 additions & 22 deletions

File tree

crates/red_knot/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub fn main() -> anyhow::Result<()> {
102102
target_version: target_version.into(),
103103
search_paths: SearchPathSettings {
104104
extra_paths,
105-
workspace_root: workspace_metadata.root().to_path_buf(),
105+
src_root: workspace_metadata.root().to_path_buf(),
106106
custom_typeshed: custom_typeshed_dir,
107107
site_packages: vec![],
108108
},

crates/red_knot/tests/file_watching.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ where
179179
{
180180
setup_with_search_paths(setup_files, |_root, workspace_path| SearchPathSettings {
181181
extra_paths: vec![],
182-
workspace_root: workspace_path.to_path_buf(),
182+
src_root: workspace_path.to_path_buf(),
183183
custom_typeshed: None,
184184
site_packages: vec![],
185185
})
@@ -695,7 +695,7 @@ fn search_path() -> anyhow::Result<()> {
695695
setup_with_search_paths([("bar.py", "import sub.a")], |root_path, workspace_path| {
696696
SearchPathSettings {
697697
extra_paths: vec![],
698-
workspace_root: workspace_path.to_path_buf(),
698+
src_root: workspace_path.to_path_buf(),
699699
custom_typeshed: None,
700700
site_packages: vec![root_path.join("site_packages")],
701701
}
@@ -755,7 +755,7 @@ fn remove_search_path() -> anyhow::Result<()> {
755755
setup_with_search_paths([("bar.py", "import sub.a")], |root_path, workspace_path| {
756756
SearchPathSettings {
757757
extra_paths: vec![],
758-
workspace_root: workspace_path.to_path_buf(),
758+
src_root: workspace_path.to_path_buf(),
759759
custom_typeshed: None,
760760
site_packages: vec![root_path.join("site_packages")],
761761
}
@@ -1173,7 +1173,7 @@ mod unix {
11731173
},
11741174
|_root, workspace| SearchPathSettings {
11751175
extra_paths: vec![],
1176-
workspace_root: workspace.to_path_buf(),
1176+
src_root: workspace.to_path_buf(),
11771177
custom_typeshed: None,
11781178
site_packages: vec![workspace.join(".venv/lib/python3.12/site-packages")],
11791179
},

crates/red_knot_module_resolver/src/resolver.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ fn try_resolve_module_resolution_settings(
123123

124124
let SearchPathSettings {
125125
extra_paths,
126-
workspace_root,
126+
src_root,
127127
custom_typeshed,
128128
site_packages,
129129
} = program.search_paths(db.upcast());
@@ -146,7 +146,7 @@ fn try_resolve_module_resolution_settings(
146146
static_search_paths.push(SearchPath::extra(system, path.clone())?);
147147
}
148148

149-
static_search_paths.push(SearchPath::first_party(system, workspace_root.clone())?);
149+
static_search_paths.push(SearchPath::first_party(system, src_root.clone())?);
150150

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

11611161
let search_paths = SearchPathSettings {
11621162
extra_paths: vec![],
1163-
workspace_root: src.clone(),
1163+
src_root: src.clone(),
11641164
custom_typeshed: Some(custom_typeshed.clone()),
11651165
site_packages: vec![site_packages],
11661166
};
@@ -1664,7 +1664,7 @@ not_a_directory
16641664
TargetVersion::default(),
16651665
SearchPathSettings {
16661666
extra_paths: vec![],
1667-
workspace_root: SystemPathBuf::from("/src"),
1667+
src_root: SystemPathBuf::from("/src"),
16681668
custom_typeshed: None,
16691669
site_packages: vec![venv_site_packages, system_site_packages],
16701670
},

crates/red_knot_module_resolver/src/testing.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ impl TestCaseBuilder<MockedTypeshed> {
224224
target_version,
225225
SearchPathSettings {
226226
extra_paths: vec![],
227-
workspace_root: src.clone(),
227+
src_root: src.clone(),
228228
custom_typeshed: Some(typeshed.clone()),
229229
site_packages: vec![site_packages.clone()],
230230
},
@@ -277,7 +277,7 @@ impl TestCaseBuilder<VendoredTypeshed> {
277277
target_version,
278278
SearchPathSettings {
279279
extra_paths: vec![],
280-
workspace_root: src.clone(),
280+
src_root: src.clone(),
281281
custom_typeshed: None,
282282
site_packages: vec![site_packages.clone()],
283283
},

crates/red_knot_python_semantic/src/semantic_model.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ mod tests {
178178
TargetVersion::Py38,
179179
SearchPathSettings {
180180
extra_paths: vec![],
181-
workspace_root: SystemPathBuf::from("/src"),
181+
src_root: SystemPathBuf::from("/src"),
182182
site_packages: vec![],
183183
custom_typeshed: None,
184184
},

crates/red_knot_python_semantic/src/types/infer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1516,7 +1516,7 @@ mod tests {
15161516
TargetVersion::Py38,
15171517
SearchPathSettings {
15181518
extra_paths: Vec::new(),
1519-
workspace_root: SystemPathBuf::from("/src"),
1519+
src_root: SystemPathBuf::from("/src"),
15201520
site_packages: vec![],
15211521
custom_typeshed: None,
15221522
},
@@ -1533,7 +1533,7 @@ mod tests {
15331533
TargetVersion::Py38,
15341534
SearchPathSettings {
15351535
extra_paths: Vec::new(),
1536-
workspace_root: SystemPathBuf::from("/src"),
1536+
src_root: SystemPathBuf::from("/src"),
15371537
site_packages: vec![],
15381538
custom_typeshed: Some(SystemPathBuf::from(typeshed)),
15391539
},

crates/red_knot_workspace/src/lint.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -317,15 +317,15 @@ mod tests {
317317
setup_db_with_root(SystemPathBuf::from("/src"))
318318
}
319319

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

323323
Program::new(
324324
&db,
325325
TargetVersion::Py38,
326326
SearchPathSettings {
327327
extra_paths: Vec::new(),
328-
workspace_root,
328+
src_root,
329329
site_packages: vec![],
330330
custom_typeshed: None,
331331
},

crates/red_knot_workspace/tests/check.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ fn setup_db(workspace_root: SystemPathBuf) -> anyhow::Result<RootDatabase> {
1212
let workspace = WorkspaceMetadata::from_path(&workspace_root, &system)?;
1313
let search_paths = SearchPathSettings {
1414
extra_paths: vec![],
15-
workspace_root,
15+
src_root: workspace_root,
1616
custom_typeshed: None,
1717
site_packages: vec![],
1818
};

crates/ruff_benchmark/benches/red_knot.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,13 +40,13 @@ fn setup_case() -> Case {
4040
])
4141
.unwrap();
4242

43-
let workspace_root = SystemPath::new("/src");
44-
let metadata = WorkspaceMetadata::from_path(workspace_root, &system).unwrap();
43+
let src_root = SystemPath::new("/src");
44+
let metadata = WorkspaceMetadata::from_path(src_root, &system).unwrap();
4545
let settings = ProgramSettings {
4646
target_version: TargetVersion::Py312,
4747
search_paths: SearchPathSettings {
4848
extra_paths: vec![],
49-
workspace_root: workspace_root.to_path_buf(),
49+
src_root: src_root.to_path_buf(),
5050
site_packages: vec![],
5151
custom_typeshed: None,
5252
},

crates/ruff_db/src/program.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ pub struct SearchPathSettings {
8585
pub extra_paths: Vec<SystemPathBuf>,
8686

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

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

0 commit comments

Comments
 (0)