Skip to content

Commit

Permalink
Rename custom-typeshed-dir to typeshed
Browse files Browse the repository at this point in the history
  • Loading branch information
MichaReiser committed Dec 12, 2024
1 parent ab25ac1 commit aa63ffa
Show file tree
Hide file tree
Showing 14 changed files with 56 additions and 61 deletions.
7 changes: 3 additions & 4 deletions crates/red_knot/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ struct Args {

/// Custom directory to use for stdlib typeshed stubs.
#[arg(long, value_name = "PATH", alias = "custom-typeshed-dir")]
typeshed_path: Option<SystemPathBuf>,
typeshed: Option<SystemPathBuf>,

/// Additional path to use as a module-resolution source (can be passed multiple times).
#[arg(long, value_name = "PATH")]
Expand Down Expand Up @@ -84,9 +84,8 @@ impl Args {
});
}

if let Some(typeshed_path) = &self.typeshed_path {
configuration.search_paths.custom_typeshed =
Some(SystemPath::absolute(typeshed_path, cli_cwd));
if let Some(typeshed) = &self.typeshed {
configuration.search_paths.typeshed = Some(SystemPath::absolute(typeshed, cli_cwd));
}

if let Some(extra_search_paths) = &self.extra_search_path {
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot/tests/file_watching.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ where
.extra_paths
.iter()
.flatten()
.chain(search_paths.custom_typeshed.iter())
.chain(search_paths.typeshed.iter())
.chain(search_paths.site_packages.iter().flat_map(|site_packages| {
if let SitePackages::Known(path) = site_packages {
path.as_slice()
Expand Down Expand Up @@ -888,7 +888,7 @@ fn changed_versions_file() -> anyhow::Result<()> {
Ok(())
},
|root_path, _workspace_path| SearchPathConfiguration {
custom_typeshed: Some(root_path.join("typeshed")),
typeshed: Some(root_path.join("typeshed")),
..SearchPathConfiguration::default()
},
)?;
Expand Down
2 changes: 1 addition & 1 deletion crates/red_knot_python_semantic/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ pub(crate) mod tests {
.context("Failed to write test files")?;

let mut search_paths = SearchPathSettings::new(src_root);
search_paths.custom_typeshed = self.custom_typeshed;
search_paths.typeshed = self.custom_typeshed;

Program::from_settings(
&db,
Expand Down
10 changes: 5 additions & 5 deletions crates/red_knot_python_semantic/src/module_resolver/path.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ mod tests {
let TestCase {
db, src, stdlib, ..
} = TestCaseBuilder::new()
.with_custom_typeshed(MockedTypeshed::default())
.with_mocked_typeshed(MockedTypeshed::default())
.build();

assert_eq!(
Expand Down Expand Up @@ -779,7 +779,7 @@ mod tests {
#[should_panic(expected = "Extension must be `pyi`; got `py`")]
fn stdlib_path_invalid_join_py() {
let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(MockedTypeshed::default())
.with_mocked_typeshed(MockedTypeshed::default())
.build();
SearchPath::custom_stdlib(&db, stdlib.parent().unwrap())
.unwrap()
Expand All @@ -791,7 +791,7 @@ mod tests {
#[should_panic(expected = "Extension must be `pyi`; got `rs`")]
fn stdlib_path_invalid_join_rs() {
let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(MockedTypeshed::default())
.with_mocked_typeshed(MockedTypeshed::default())
.build();
SearchPath::custom_stdlib(&db, stdlib.parent().unwrap())
.unwrap()
Expand Down Expand Up @@ -822,7 +822,7 @@ mod tests {
#[test]
fn relativize_stdlib_path_errors() {
let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(MockedTypeshed::default())
.with_mocked_typeshed(MockedTypeshed::default())
.build();

let root = SearchPath::custom_stdlib(&db, stdlib.parent().unwrap()).unwrap();
Expand Down Expand Up @@ -870,7 +870,7 @@ mod tests {
python_version: PythonVersion,
) -> (TestDb, SearchPath) {
let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(typeshed)
.with_mocked_typeshed(typeshed)
.with_python_version(python_version)
.build();
let stdlib = SearchPath::custom_stdlib(&db, stdlib.parent().unwrap()).unwrap();
Expand Down
42 changes: 19 additions & 23 deletions crates/red_knot_python_semantic/src/module_resolver/resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ impl SearchPaths {
let SearchPathSettings {
extra_paths,
src_root,
custom_typeshed,
typeshed,
site_packages: site_packages_paths,
} = settings;

Expand All @@ -180,17 +180,13 @@ impl SearchPaths {
tracing::debug!("Adding first-party search path '{src_root}'");
static_paths.push(SearchPath::first_party(system, src_root.to_path_buf())?);

let (typeshed_versions, stdlib_path) = if let Some(custom_typeshed) = custom_typeshed {
let custom_typeshed = canonicalize(custom_typeshed, system);
tracing::debug!("Adding custom-stdlib search path '{custom_typeshed}'");
let (typeshed_versions, stdlib_path) = if let Some(typeshed) = typeshed {
let typeshed = canonicalize(typeshed, system);
tracing::debug!("Adding custom-stdlib search path '{typeshed}'");

files.try_add_root(
db.upcast(),
&custom_typeshed,
FileRootKind::LibrarySearchPath,
);
files.try_add_root(db.upcast(), &typeshed, FileRootKind::LibrarySearchPath);

let versions_path = custom_typeshed.join("stdlib/VERSIONS");
let versions_path = typeshed.join("stdlib/VERSIONS");

let versions_content = system.read_to_string(&versions_path).map_err(|error| {
SearchPathValidationError::FailedToReadVersionsFile {
Expand All @@ -201,7 +197,7 @@ impl SearchPaths {

let parsed: TypeshedVersions = versions_content.parse()?;

let search_path = SearchPath::custom_stdlib(db, &custom_typeshed)?;
let search_path = SearchPath::custom_stdlib(db, &typeshed)?;

(parsed, search_path)
} else {
Expand Down Expand Up @@ -771,7 +767,7 @@ mod tests {

let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_src_files(SRC)
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand All @@ -789,7 +785,7 @@ mod tests {
};

let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -842,7 +838,7 @@ mod tests {
};

let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -887,7 +883,7 @@ mod tests {
};

let TestCase { db, .. } = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -931,7 +927,7 @@ mod tests {
};

let TestCase { db, stdlib, .. } = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY39)
.build();

Expand Down Expand Up @@ -973,7 +969,7 @@ mod tests {
};

let TestCase { db, .. } = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY39)
.build();

Expand All @@ -997,7 +993,7 @@ mod tests {

let TestCase { db, src, .. } = TestCaseBuilder::new()
.with_src_files(SRC)
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -1294,7 +1290,7 @@ mod tests {
search_paths: SearchPathSettings {
extra_paths: vec![],
src_root: src.clone(),
custom_typeshed: Some(custom_typeshed),
typeshed: Some(custom_typeshed),
site_packages: SitePackages::Known(vec![site_packages]),
},
},
Expand Down Expand Up @@ -1420,7 +1416,7 @@ mod tests {
site_packages,
..
} = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -1468,7 +1464,7 @@ mod tests {
src,
..
} = TestCaseBuilder::new()
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -1508,7 +1504,7 @@ mod tests {
..
} = TestCaseBuilder::new()
.with_src_files(SRC)
.with_custom_typeshed(TYPESHED)
.with_mocked_typeshed(TYPESHED)
.with_python_version(PythonVersion::PY38)
.build();

Expand Down Expand Up @@ -1799,7 +1795,7 @@ not_a_directory
search_paths: SearchPathSettings {
extra_paths: vec![],
src_root: SystemPathBuf::from("/src"),
custom_typeshed: None,
typeshed: None,
site_packages: SitePackages::Known(vec![
venv_site_packages,
system_site_packages,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ pub(crate) struct UnspecifiedTypeshed;
/// const TYPESHED = MockedTypeshed { ... };
///
/// let test_case = resolver_test_case()
/// .with_custom_typeshed(TYPESHED)
/// .with_mocked_typeshed(TYPESHED)
/// .with_python_version(...)
/// .build();
///
Expand Down Expand Up @@ -169,7 +169,7 @@ impl TestCaseBuilder<UnspecifiedTypeshed> {
}

/// Use a mock typeshed directory for this test case
pub(crate) fn with_custom_typeshed(
pub(crate) fn with_mocked_typeshed(
self,
typeshed: MockedTypeshed,
) -> TestCaseBuilder<MockedTypeshed> {
Expand All @@ -195,7 +195,7 @@ impl TestCaseBuilder<UnspecifiedTypeshed> {
stdlib: _,
site_packages,
python_version,
} = self.with_custom_typeshed(MockedTypeshed::default()).build();
} = self.with_mocked_typeshed(MockedTypeshed::default()).build();

TestCase {
db,
Expand Down Expand Up @@ -230,7 +230,7 @@ impl TestCaseBuilder<MockedTypeshed> {
search_paths: SearchPathSettings {
extra_paths: vec![],
src_root: src.clone(),
custom_typeshed: Some(typeshed.clone()),
typeshed: Some(typeshed.clone()),
site_packages: SitePackages::Known(vec![site_packages.clone()]),
},
},
Expand Down
4 changes: 2 additions & 2 deletions crates/red_knot_python_semantic/src/program.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub struct SearchPathSettings {
/// 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,
/// bundled as a zip file in the binary
pub custom_typeshed: Option<SystemPathBuf>,
pub typeshed: Option<SystemPathBuf>,

/// The path to the user's `site-packages` directory, where third-party packages from ``PyPI`` are installed.
pub site_packages: SitePackages,
Expand All @@ -86,7 +86,7 @@ impl SearchPathSettings {
Self {
src_root,
extra_paths: vec![],
custom_typeshed: None,
typeshed: None,
site_packages: SitePackages::Known(vec![]),
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/red_knot_workspace/src/workspace/settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,10 +57,10 @@ pub struct SearchPathConfiguration {
/// The root of the workspace, used for finding first-party modules.
pub src_root: Option<SystemPathBuf>,

/// Optional path to a "custom typeshed" directory on disk for us to use for standard-library types.
/// Optional path to a "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,
/// bundled as a zip file in the binary
pub custom_typeshed: Option<SystemPathBuf>,
pub typeshed: Option<SystemPathBuf>,

/// The path to the user's `site-packages` directory, where third-party packages from ``PyPI`` are installed.
pub site_packages: Option<SitePackages>,
Expand All @@ -79,7 +79,7 @@ impl SearchPathConfiguration {
.clone()
.src_root
.unwrap_or_else(|| workspace_root.to_path_buf()),
custom_typeshed: self.custom_typeshed.clone(),
typeshed: self.typeshed.clone(),
site_packages,
}
}
Expand All @@ -91,8 +91,8 @@ impl SearchPathConfiguration {
if let Some(src_root) = with.src_root {
self.src_root.get_or_insert(src_root);
}
if let Some(custom_typeshed) = with.custom_typeshed {
self.custom_typeshed.get_or_insert(custom_typeshed);
if let Some(typeshed) = with.typeshed {
self.typeshed.get_or_insert(typeshed);
}
if let Some(site_packages) = with.site_packages {
self.site_packages.get_or_insert(site_packages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WorkspaceMetadata(
search_paths: SearchPathConfiguration(
extra_paths: None,
src_root: None,
custom_typeshed: None,
typeshed: None,
site_packages: None,
),
),
Expand All @@ -29,7 +29,7 @@ WorkspaceMetadata(
search_paths: SearchPathSettings(
extra_paths: [],
src_root: "/app",
custom_typeshed: None,
typeshed: None,
site_packages: Known([]),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WorkspaceMetadata(
search_paths: SearchPathConfiguration(
extra_paths: None,
src_root: None,
custom_typeshed: None,
typeshed: None,
site_packages: None,
),
),
Expand All @@ -29,7 +29,7 @@ WorkspaceMetadata(
search_paths: SearchPathSettings(
extra_paths: [],
src_root: "/app",
custom_typeshed: None,
typeshed: None,
site_packages: Known([]),
),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ WorkspaceMetadata(
search_paths: SearchPathConfiguration(
extra_paths: None,
src_root: None,
custom_typeshed: None,
typeshed: None,
site_packages: None,
),
),
Expand All @@ -29,7 +29,7 @@ WorkspaceMetadata(
search_paths: SearchPathSettings(
extra_paths: [],
src_root: "/app",
custom_typeshed: None,
typeshed: None,
site_packages: Known([]),
),
),
Expand Down
Loading

0 comments on commit aa63ffa

Please sign in to comment.