impactsense_parser/
python_stdlib.rs1use std::collections::HashSet;
3use std::sync::OnceLock;
4
5fn stdlib_names() -> &'static HashSet<String> {
6 static SET: OnceLock<HashSet<String>> = OnceLock::new();
7 SET.get_or_init(|| {
8 include_str!("python_stdlib_modules.txt")
9 .lines()
10 .map(|l| l.trim().to_string())
11 .filter(|l| !l.is_empty())
12 .collect()
13 })
14}
15
16pub fn is_python_stdlib_top_level(import_dotted: &str) -> bool {
18 let top = import_dotted
19 .trim()
20 .split('.')
21 .next()
22 .unwrap_or("")
23 .trim();
24 !top.is_empty() && stdlib_names().contains(top)
25}