MCPcopy Index your code
hub / github.com/RustPython/RustPython / _resolve_module_name

Function _resolve_module_name

scripts/update_lib/cmd_deps.py:332–383  ·  view source on GitHub ↗

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,
)

Source from the content-addressed store, hash-verified

330
331
332def _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
386def show_deps(

Callers 1

show_depsFunction · 0.85

Calls 12

resolve_test_to_libFunction · 0.90
resolve_hard_dep_parentFunction · 0.90
get_lib_pathsFunction · 0.90
get_test_pathsFunction · 0.90
_build_test_import_graphFunction · 0.90
sortedFunction · 0.85
setFunction · 0.85
anyFunction · 0.50
startswithMethod · 0.45
existsMethod · 0.45
itemsMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected