Checks whether a module is installed without importing it. Use this for a lightweight check and lazy imports. Parameters ---------- module : str Name of the module. minversion : str, optional Minimum version of the module Returns ------- available :
(module: str, minversion: str | None = None)
| 38 | |
| 39 | @lru_cache |
| 40 | def module_available(module: str, minversion: str | None = None) -> bool: |
| 41 | """Checks whether a module is installed without importing it. |
| 42 | |
| 43 | Use this for a lightweight check and lazy imports. |
| 44 | |
| 45 | Parameters |
| 46 | ---------- |
| 47 | module : str |
| 48 | Name of the module. |
| 49 | minversion : str, optional |
| 50 | Minimum version of the module |
| 51 | |
| 52 | Returns |
| 53 | ------- |
| 54 | available : bool |
| 55 | Whether the module is installed. |
| 56 | """ |
| 57 | if importlib.util.find_spec(module) is None: |
| 58 | return False |
| 59 | |
| 60 | if minversion is not None: |
| 61 | version = importlib.metadata.version(module) |
| 62 | |
| 63 | return Version(version) >= Version(minversion) |
| 64 | |
| 65 | return True |
| 66 | |
| 67 | |
| 68 | def is_dask_collection(x: object) -> TypeGuard[DaskCollection]: |
no outgoing calls
searching dependent graphs…