From 59c31c8a9f64bfb81eeba86ae3466786aed35182 Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 3 Apr 2021 22:29:36 +0100 Subject: [PATCH 1/2] enhance min/exact version Signed-off-by: Wenqi Li --- monai/utils/module.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/monai/utils/module.py b/monai/utils/module.py index c12eaf101d..1983fcec21 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -95,6 +95,8 @@ def min_version(the_module, min_version_str: str = "") -> bool: Returns True if the module's version is greater or equal to the 'min_version'. When min_version_str is not provided, it always returns True. """ + if not hasattr(the_module, "__version__"): + return True # min_version is the default, shouldn't be noisy if min_version_str: mod_version = tuple(int(x) for x in the_module.__version__.split(".")[:2]) required = tuple(int(x) for x in min_version_str.split(".")[:2]) @@ -106,6 +108,8 @@ def exact_version(the_module, version_str: str = "") -> bool: """ Returns True if the module's __version__ matches version_str """ + if not hasattr(the_module, "__version__"): + return False return bool(the_module.__version__ == version_str) From b9ceef686a4e072e5d6bc7c535cdaf9d4565c96d Mon Sep 17 00:00:00 2001 From: Wenqi Li Date: Sat, 3 Apr 2021 23:01:20 +0100 Subject: [PATCH 2/2] adds warning msg Signed-off-by: Wenqi Li --- monai/utils/module.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/monai/utils/module.py b/monai/utils/module.py index 1983fcec21..afb4dd9f08 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -11,6 +11,7 @@ import inspect import sys +import warnings from importlib import import_module from pkgutil import walk_packages from re import match @@ -96,6 +97,7 @@ def min_version(the_module, min_version_str: str = "") -> bool: When min_version_str is not provided, it always returns True. """ if not hasattr(the_module, "__version__"): + warnings.warn(f"{the_module} has no attribute __version__ in min_version check.") return True # min_version is the default, shouldn't be noisy if min_version_str: mod_version = tuple(int(x) for x in the_module.__version__.split(".")[:2]) @@ -109,6 +111,7 @@ def exact_version(the_module, version_str: str = "") -> bool: Returns True if the module's __version__ matches version_str """ if not hasattr(the_module, "__version__"): + warnings.warn(f"{the_module} has no attribute __version__ in exact_version check.") return False return bool(the_module.__version__ == version_str)