Skip to content

Commit 8846541

Browse files
KumoLiupre-commit-ci[bot]
authored andcommitted
Fix module can not import correctly issue (Project-MONAI#8015)
Fixes Project-MONAI#8014 ### Types of changes <!--- Put an `x` in all the boxes that apply, and remove the not applicable items --> - [x] Non-breaking change (fix or new feature that would not break existing functionality). - [ ] Breaking change (fix or new feature that would cause existing functionality to change). - [ ] New tests added to cover the changes. - [ ] Integration tests passed locally by running `./runtests.sh -f -u --net --coverage`. - [x] Quick tests passed locally by running `./runtests.sh --quick --unittests --disttests`. - [ ] In-line docstrings updated. - [ ] Documentation updated, tested `make html` command in the `docs/` folder. --------- Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
1 parent ab14b50 commit 8846541

1 file changed

Lines changed: 4 additions & 3 deletions

File tree

monai/utils/module.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414
import enum
1515
import functools
16-
import importlib.util
1716
import os
1817
import pdb
1918
import re
@@ -209,11 +208,13 @@ def load_submodules(
209208
):
210209
if (is_pkg or load_all) and name not in sys.modules and match(exclude_pattern, name) is None:
211210
try:
211+
mod = import_module(name)
212212
mod_spec = importer.find_spec(name) # type: ignore
213213
if mod_spec and mod_spec.loader:
214-
mod = importlib.util.module_from_spec(mod_spec)
215-
mod_spec.loader.exec_module(mod)
214+
loader = mod_spec.loader
215+
loader.exec_module(mod)
216216
submodules.append(mod)
217+
217218
except OptionalImportError:
218219
pass # could not import the optional deps., they are ignored
219220
except ImportError as e:

0 commit comments

Comments
 (0)