Resolve module name through redirects. Returns a list of module names (usually 1, but test support files may expand to multiple).
(
name: str,
cpython_prefix: str,
lib_prefix: str,
)
| 330 | |
| 331 | |
| 332 | def _resolve_module_name( |
| 333 | name: str, |
| 334 | cpython_prefix: str, |
| 335 | lib_prefix: str, |
| 336 | ) -> list[str]: |
| 337 | """Resolve module name through redirects. |
| 338 | |
| 339 | Returns a list of module names (usually 1, but test support files may expand to multiple). |
| 340 | """ |
| 341 | import pathlib |
| 342 | |
| 343 | from update_lib.deps import ( |
| 344 | _build_test_import_graph, |
| 345 | get_lib_paths, |
| 346 | get_test_paths, |
| 347 | resolve_hard_dep_parent, |
| 348 | resolve_test_to_lib, |
| 349 | ) |
| 350 | |
| 351 | # Resolve test to library group (e.g., test_urllib2 -> urllib) |
| 352 | if name.startswith("test_"): |
| 353 | lib_group = resolve_test_to_lib(name) |
| 354 | if lib_group: |
| 355 | return [lib_group] |
| 356 | name = name[5:] |
| 357 | |
| 358 | # Resolve hard_dep to parent |
| 359 | parent = resolve_hard_dep_parent(name, cpython_prefix) |
| 360 | if parent: |
| 361 | return [parent] |
| 362 | |
| 363 | # Check if it's a valid module |
| 364 | lib_paths = get_lib_paths(name, cpython_prefix) |
| 365 | test_paths = get_test_paths(name, cpython_prefix) |
| 366 | if any(p.exists() for p in lib_paths) or any(p.exists() for p in test_paths): |
| 367 | return [name] |
| 368 | |
| 369 | # Check for test support files (e.g., string_tests -> bytes, str, userstring) |
| 370 | test_support_path = pathlib.Path(cpython_prefix) / "Lib" / "test" / f"{name}.py" |
| 371 | if test_support_path.exists(): |
| 372 | test_dir = pathlib.Path(lib_prefix) / "test" |
| 373 | if test_dir.exists(): |
| 374 | import_graph, _ = _build_test_import_graph(test_dir) |
| 375 | importing_tests = [] |
| 376 | for file_key, imports in import_graph.items(): |
| 377 | if name in imports and file_key.startswith("test_"): |
| 378 | importing_tests.append(file_key) |
| 379 | if importing_tests: |
| 380 | # Resolve test names to module names (test_bytes -> bytes) |
| 381 | return sorted(set(t[5:] for t in importing_tests)) |
| 382 | |
| 383 | return [name] |
| 384 | |
| 385 | |
| 386 | def show_deps( |
no test coverage detected