From b76d04b7c1cc9bb7b860657c1510ab12aa6300a7 Mon Sep 17 00:00:00 2001 From: YunLiu <55491388+KumoLiu@users.noreply.github.com> Date: Wed, 14 Aug 2024 00:25:42 +0800 Subject: [PATCH 1/2] fix #8014 Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> --- monai/utils/module.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 251232d62f..5bd8fdd530 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -209,11 +209,13 @@ def load_submodules( ): if (is_pkg or load_all) and name not in sys.modules and match(exclude_pattern, name) is None: try: + mod = import_module(name) mod_spec = importer.find_spec(name) # type: ignore if mod_spec and mod_spec.loader: - mod = importlib.util.module_from_spec(mod_spec) - mod_spec.loader.exec_module(mod) + loader = mod_spec.loader + loader.exec_module(mod) submodules.append(mod) + except OptionalImportError: pass # could not import the optional deps., they are ignored except ImportError as e: From d0a31a43d3ecb526bd0dfdef5808defe3271633a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 13 Aug 2024 16:27:33 +0000 Subject: [PATCH 2/2] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- monai/utils/module.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/monai/utils/module.py b/monai/utils/module.py index 5bd8fdd530..1ac8140b39 100644 --- a/monai/utils/module.py +++ b/monai/utils/module.py @@ -13,7 +13,6 @@ import enum import functools -import importlib.util import os import pdb import re @@ -215,7 +214,7 @@ def load_submodules( loader = mod_spec.loader loader.exec_module(mod) submodules.append(mod) - + except OptionalImportError: pass # could not import the optional deps., they are ignored except ImportError as e: