From 65fbc339b7b627b9d0d03370a5ad1640088758ec Mon Sep 17 00:00:00 2001 From: Young Joon Lee Date: Mon, 24 Jul 2023 21:59:48 +0900 Subject: [PATCH] fix(utils): add is_importable method to PKGs class --- src/hyfi/utils/packages.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/hyfi/utils/packages.py b/src/hyfi/utils/packages.py index 9eaca446..f047ecf7 100644 --- a/src/hyfi/utils/packages.py +++ b/src/hyfi/utils/packages.py @@ -212,3 +212,8 @@ def get_caller_module_name(caller_stack_depth: int = 2) -> str: f"Error getting caller module name at depth {caller_stack_depth}: {e}" ) return "" + + @staticmethod + def is_importable(module_name: str) -> bool: + module_spec = importlib.util.find_spec(module_name) # type: ignore + return module_spec is not None