Skip to content

Commit

Permalink
Fix module can not import correctly issue (#8015)
Browse files Browse the repository at this point in the history
Fixes #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>
  • Loading branch information
KumoLiu and pre-commit-ci[bot] authored Aug 14, 2024
1 parent 34ce94d commit 4877767
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions monai/utils/module.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import enum
import functools
import importlib.util
import os
import pdb
import re
Expand Down Expand Up @@ -209,11 +208,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:
Expand Down

0 comments on commit 4877767

Please sign in to comment.