MCPcopy Create free account
hub / github.com/FSoft-AI4Code/CodeText-parser / module_available

Function module_available

src/codetext/utils/imports.py:18–38  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

16
17
18def 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

Callers

nothing calls this directly

Calls 1

_package_availableFunction · 0.85

Tested by

no test coverage detected