Find module and determine __all__ for a Python 3 module. Return None if the module is a C or pyc-only module. Return (module_path, __all__) if it is a Python module. Raise CantImport if import failed.
(
inspect: ModuleInspect, module: str, verbose: bool
)
| 107 | |
| 108 | |
| 109 | def find_module_path_and_all_py3( |
| 110 | inspect: ModuleInspect, module: str, verbose: bool |
| 111 | ) -> tuple[str | None, list[str] | None] | None: |
| 112 | """Find module and determine __all__ for a Python 3 module. |
| 113 | |
| 114 | Return None if the module is a C or pyc-only module. |
| 115 | Return (module_path, __all__) if it is a Python module. |
| 116 | Raise CantImport if import failed. |
| 117 | """ |
| 118 | if module in NOT_IMPORTABLE_MODULES: |
| 119 | raise CantImport(module, "") |
| 120 | |
| 121 | # TODO: Support custom interpreters. |
| 122 | if verbose: |
| 123 | print(f"Trying to import {module!r} for runtime introspection") |
| 124 | try: |
| 125 | mod = inspect.get_package_properties(module) |
| 126 | except InspectError as e: |
| 127 | # Fall back to finding the module using sys.path. |
| 128 | path = find_module_path_using_sys_path(module, sys.path) |
| 129 | if path is None: |
| 130 | raise CantImport(module, str(e)) from e |
| 131 | return path, None |
| 132 | if mod.is_c_module: |
| 133 | return None |
| 134 | return mod.file, mod.all |
| 135 | |
| 136 | |
| 137 | @contextmanager |
no test coverage detected
searching dependent graphs…