Get all imports from a library file. Args: name: Module name cpython_prefix: CPython directory prefix Returns: Frozenset of all imported module names
(name: str, cpython_prefix: str)
| 965 | |
| 966 | @functools.cache |
| 967 | def get_all_imports(name: str, cpython_prefix: str) -> frozenset[str]: |
| 968 | """Get all imports from a library file. |
| 969 | |
| 970 | Args: |
| 971 | name: Module name |
| 972 | cpython_prefix: CPython directory prefix |
| 973 | |
| 974 | Returns: |
| 975 | Frozenset of all imported module names |
| 976 | """ |
| 977 | all_imports = set() |
| 978 | for lib_path in get_lib_paths(name, cpython_prefix): |
| 979 | if lib_path.exists(): |
| 980 | for _, content in read_python_files(lib_path): |
| 981 | all_imports.update(parse_lib_imports(content)) |
| 982 | |
| 983 | # Remove self |
| 984 | all_imports.discard(name) |
| 985 | return frozenset(all_imports) |
| 986 | |
| 987 | |
| 988 | @functools.cache |
no test coverage detected