Coverage for transformer_lens/utilities/library_utils.py: 100%
4 statements
« prev ^ index » next coverage.py v7.10.1, created at 2026-04-30 01:33 +0000
« prev ^ index » next coverage.py v7.10.1, created at 2026-04-30 01:33 +0000
1"""Library availability utilities.
3Utilities for checking if optional libraries are available without importing them.
4"""
6import importlib.util
7import sys
10def is_library_available(name: str) -> bool:
11 """
12 Checks if a library is installed in the current environment without importing it.
13 Prevents crash or segmentation fault.
15 Args:
16 name: The name of the library to check (e.g., "wandb", "transformers")
18 Returns:
19 True if the library is available, False otherwise
20 """
21 return name in sys.modules or importlib.util.find_spec(name) is not None