Skip to content

Commit

Permalink
[red-knot] Move typeshed VERSIONS parser to the module resolver crate
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexWaygood committed Jun 21, 2024
1 parent 3277d03 commit d3b495a
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 29 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions crates/red_knot/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ red_knot_module_resolver = { workspace = true }

ruff_python_parser = { workspace = true }
ruff_python_ast = { workspace = true }
ruff_python_stdlib = { workspace = true }
ruff_text_size = { workspace = true }
ruff_index = { workspace = true }
ruff_notebook = { workspace = true }
Expand All @@ -39,7 +38,6 @@ tracing-subscriber = { workspace = true }
tracing-tree = { workspace = true }

[dev-dependencies]
insta = { workspace = true }
tempfile = { workspace = true }

[lints]
Expand Down
1 change: 0 additions & 1 deletion crates/red_knot/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ mod parse;
pub mod program;
mod semantic;
pub mod source;
pub mod typeshed_versions;
pub mod watch;

pub(crate) type FxDashMap<K, V> = dashmap::DashMap<K, V, BuildHasherDefault<FxHasher>>;
Expand Down
2 changes: 2 additions & 0 deletions crates/red_knot_module_resolver/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ license = { workspace = true }
ruff_db = { workspace = true }
ruff_python_stdlib = { workspace = true }

rustc-hash = { workspace = true }
salsa = { workspace = true }
smol_str = { workspace = true }
tracing = { workspace = true }
Expand All @@ -25,6 +26,7 @@ zip = { workspace = true }

[dev-dependencies]
anyhow = { workspace = true }
insta = { workspace = true }
tempfile = { workspace = true }

[lints]
Expand Down
1 change: 1 addition & 0 deletions crates/red_knot_module_resolver/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ mod typeshed;
pub use db::{Db, Jar};
pub use module::{ModuleKind, ModuleName};
pub use resolver::{resolve_module, set_module_resolution_settings, ModuleResolutionSettings};
pub use typeshed::versions::TypeshedVersions;
2 changes: 2 additions & 0 deletions crates/red_knot_module_resolver/src/typeshed.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
pub(crate) mod versions;

#[cfg(test)]
mod tests {
use std::io::{self, Read};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -320,30 +320,28 @@ mod tests {
#[allow(unsafe_code)]
const ONE: NonZeroU16 = unsafe { NonZeroU16::new_unchecked(1) };

// TODO(Alex): move VERSIONS parsing logic to red_knot_module_resolver, add this test back
//
// #[test]
// fn can_parse_vendored_versions_file() {
// let versions_data = include_str!(concat!(
// env!("CARGO_MANIFEST_DIR"),
// "/vendor/typeshed/stdlib/VERSIONS"
// ));

// let versions = TypeshedVersions::from_str(versions_data).unwrap();
// assert!(versions.len() > 100);
// assert!(versions.len() < 1000);

// assert!(versions.contains_module("asyncio"));
// assert!(versions.module_exists_on_version("asyncio", SupportedPyVersion::Py310));

// assert!(versions.contains_module("asyncio.staggered"));
// assert!(versions.module_exists_on_version("asyncio.staggered", SupportedPyVersion::Py38));
// assert!(!versions.module_exists_on_version("asyncio.staggered", SupportedPyVersion::Py37));

// assert!(versions.contains_module("audioop"));
// assert!(versions.module_exists_on_version("audioop", SupportedPyVersion::Py312));
// assert!(!versions.module_exists_on_version("audioop", SupportedPyVersion::Py313));
// }
#[test]
fn can_parse_vendored_versions_file() {
let versions_data = include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/vendor/typeshed/stdlib/VERSIONS"
));

let versions = TypeshedVersions::from_str(versions_data).unwrap();
assert!(versions.len() > 100);
assert!(versions.len() < 1000);

assert!(versions.contains_module("asyncio"));
assert!(versions.module_exists_on_version("asyncio", SupportedPyVersion::Py310));

assert!(versions.contains_module("asyncio.staggered"));
assert!(versions.module_exists_on_version("asyncio.staggered", SupportedPyVersion::Py38));
assert!(!versions.module_exists_on_version("asyncio.staggered", SupportedPyVersion::Py37));

assert!(versions.contains_module("audioop"));
assert!(versions.module_exists_on_version("audioop", SupportedPyVersion::Py312));
assert!(!versions.module_exists_on_version("audioop", SupportedPyVersion::Py313));
}

#[test]
fn can_parse_mock_versions_file() {
Expand Down

0 comments on commit d3b495a

Please sign in to comment.