Skip to content

Commit a525d25

Browse files
committed
programs.get_version: now raises ImportError when module is not installed (the
previous return values were ambiguous: was returning version number is module was installed, None if module was installed but version number could not be retrieved, and False when module was not installed). The old implementation has lead to a bug when trying to handle missing pylint dependency which is fixed by this revision too.
1 parent 48b27f7 commit a525d25

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

spyderlib/dependencies.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ def __init__(self, modname, features, required_version,
2828
self.features = features
2929
self.required_version = required_version
3030
if installed_version is None:
31-
self.installed_version = programs.get_module_version(modname)
31+
try:
32+
self.installed_version = programs.get_module_version(modname)
33+
except ImportError:
34+
# Module is not installed
35+
self.installed_version = None
3236
else:
3337
self.installed_version = installed_version
3438

spyderlib/utils/programs.py

+5-10
Original file line numberDiff line numberDiff line change
@@ -202,14 +202,8 @@ def check_version(actver, version, cmp_op):
202202

203203

204204
def get_module_version(module_name):
205-
"""Get module version.
206-
207-
Return module version, return False if module is not installed,
208-
return None if module is installed but version can't be retrieved"""
209-
try:
210-
mod = __import__(module_name)
211-
except ImportError:
212-
return False
205+
"""Return module version or None if version can't be retrieved."""
206+
mod = __import__(module_name)
213207
return getattr(mod, '__version__', getattr(mod, 'VERSION', None))
214208

215209

@@ -262,8 +256,9 @@ def is_module_installed(module_name, version=None, installed_version=None,
262256
return True
263257
else:
264258
if installed_version is None:
265-
actver = get_module_version(module_name)
266-
if actver is not None and not actver:
259+
try:
260+
actver = get_module_version(module_name)
261+
except ImportError:
267262
# Module is not installed
268263
return False
269264
else:

spyderlib/widgets/dependencies.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,9 @@ def test():
153153
from spyderlib import dependencies
154154

155155
# Test sample
156-
dependencies.add("IPython", "Enhanced Python interpreter", ">=0.13")
157-
dependencies.add("matplotlib", "Interactive data plotting", ">=1.0")
158-
dependencies.add("sympy", "Symbolic Mathematics", ">=10.0")
156+
# dependencies.add("IPython", "Enhanced Python interpreter", ">=0.13")
157+
# dependencies.add("matplotlib", "Interactive data plotting", ">=1.0")
158+
# dependencies.add("sympy", "Symbolic Mathematics", ">=10.0")
159159
dependencies.add("foo", "Non-existent module", ">=1.0")
160160

161161
from spyderlib.utils.qthelpers import qapplication

0 commit comments

Comments
 (0)