Find Lib modules (full paths) that import module_name or any of its submodules.
(
module_name: str, lib_import_graph: dict[str, set[str]]
)
| 1516 | |
| 1517 | |
| 1518 | def _get_lib_modules_importing( |
| 1519 | module_name: str, lib_import_graph: dict[str, set[str]] |
| 1520 | ) -> set[str]: |
| 1521 | """Find Lib modules (full paths) that import module_name or any of its submodules.""" |
| 1522 | importers: set[str] = set() |
| 1523 | target_top = module_name.split(".")[0] |
| 1524 | |
| 1525 | for full_path, imports in lib_import_graph.items(): |
| 1526 | if full_path.split(".")[0] == target_top: |
| 1527 | continue # Skip same package |
| 1528 | # Match if module imports target OR any submodule of target |
| 1529 | # e.g., for "xml": match imports of "xml", "xml.parsers", "xml.etree.ElementTree" |
| 1530 | matches = any( |
| 1531 | imp == module_name or imp.startswith(module_name + ".") for imp in imports |
| 1532 | ) |
| 1533 | if matches: |
| 1534 | importers.add(full_path) |
| 1535 | |
| 1536 | return importers |
| 1537 | |
| 1538 | |
| 1539 | def _consolidate_submodules( |
no test coverage detected