Skip to main content

impactsense_parser/
python_common_external.rs

1//! Common third-party / optional top-level names (PyPI, Sphinx, etc.).
2//! Imports whose first segment is listed here are not logged as unresolved when
3//! they do not map to scanned files (same idea as stdlib filtering).
4use std::collections::HashSet;
5use std::sync::OnceLock;
6
7fn external_top_level_names() -> &'static HashSet<String> {
8    static SET: OnceLock<HashSet<String>> = OnceLock::new();
9    SET.get_or_init(|| {
10        include_str!("python_common_external_modules.txt")
11            .lines()
12            .map(|l| l.trim().to_string())
13            .filter(|l| !l.is_empty() && !l.starts_with('#'))
14            .collect()
15    })
16}
17
18/// True if the first component of a dotted import is a known external package name.
19pub fn is_python_common_external_top_level(import_dotted: &str) -> bool {
20    let top = import_dotted
21        .trim()
22        .split('.')
23        .next()
24        .unwrap_or("")
25        .trim();
26    !top.is_empty() && external_top_level_names().contains(top)
27}