Check if a module path is available in your environment. Source: pytorch_lightning/utilities/imports.py .. code-block:: python >>> module_available('os') True >>> module_available('os.bla') False >>> module_available('bla.bla') False
(module_path: str)
| 16 | |
| 17 | |
| 18 | def module_available(module_path: str) -> bool: |
| 19 | """Check if a module path is available in your environment. |
| 20 | Source: pytorch_lightning/utilities/imports.py |
| 21 | .. code-block:: python |
| 22 | |
| 23 | >>> module_available('os') |
| 24 | True |
| 25 | >>> module_available('os.bla') |
| 26 | False |
| 27 | >>> module_available('bla.bla') |
| 28 | False |
| 29 | """ |
| 30 | module_names = module_path.split(".") |
| 31 | if not _package_available(module_names[0]): |
| 32 | return False |
| 33 | module = importlib.import_module(module_names[0]) |
| 34 | for name in module_names[1:]: |
| 35 | if not hasattr(module, name): |
| 36 | return False |
| 37 | module = getattr(module, name) |
| 38 | return True |
nothing calls this directly
no test coverage detected