Skip to content

Commit a073580

Browse files
committed
ENH: Use pkgutil.find_loader to avoid loading modules on __init__
1 parent 3a1ddad commit a073580

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

nipype/interfaces/base/core.py

+2-4
Original file line numberDiff line numberDiff line change
@@ -1164,12 +1164,10 @@ class LibraryBaseInterface(BaseInterface):
11641164
def __init__(self, check_import=True, *args, **kwargs):
11651165
super(LibraryBaseInterface, self).__init__(*args, **kwargs)
11661166
if check_import:
1167-
import importlib
1167+
import pkgutil
11681168
failed_imports = []
11691169
for pkg in (self._pkg,) + tuple(self.imports):
1170-
try:
1171-
importlib.import_module(pkg)
1172-
except ImportError:
1170+
if pkgutil.find_loader(pkg) is None:
11731171
failed_imports.append(pkg)
11741172
if failed_imports:
11751173
iflogger.warning('Unable to import %s; %s interface may fail to '

0 commit comments

Comments
 (0)