Skip to content

Commit f9e30bb

Browse files
committed
Fixed falsely giving error for egg modules
False error was being given for egg modules that have not been unzipped but were able to import. Now __import__ is used for those cases as a last check.
1 parent ecc0e32 commit f9e30bb

File tree

1 file changed

+14
-7
lines changed

1 file changed

+14
-7
lines changed

workspace_tools/utils.py

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,17 +110,24 @@ def check_required_modules(required_modules, verbose=True):
110110
@return returns True if all modules are installed already
111111
"""
112112
import imp
113-
all_modules_found = True
114113
not_installed_modules = []
115114
for module_name in required_modules:
116115
try:
117116
imp.find_module(module_name)
118117
except ImportError as e:
119-
all_modules_found = False
120-
not_installed_modules.append(module_name)
121-
if verbose:
122-
print "Error: %s"% e
118+
# We also test against a rare case: module is an egg file
119+
try:
120+
__import__(module_name)
121+
except ImportError as e:
122+
not_installed_modules.append(module_name)
123+
if verbose:
124+
print "Error: %s" % e
125+
123126
if verbose:
124-
if not all_modules_found:
127+
if not_installed_modules:
125128
print "Warning: Module(s) %s not installed. Please install required module(s) before using this script."% (', '.join(not_installed_modules))
126-
return all_modules_found
129+
130+
if not_installed_modules:
131+
return False
132+
else:
133+
return True

0 commit comments

Comments
 (0)