Skip to content

Commit b6be263

Browse files
committed
add check_version utility
using LooseVersion and explicitly catching TypeError, rather than the NumericalVersion subclass.
1 parent 7841ef8 commit b6be263

3 files changed

Lines changed: 20 additions & 7 deletions

File tree

IPython/external/qt.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"""
88

99
import os
10-
from IPython.utils.version import NumericalVersion as V
10+
from IPython.utils.version import check_version
1111
# Available APIs.
1212
QT_API_PYQT = 'pyqt'
1313
QT_API_PYSIDE = 'pyside'
@@ -26,7 +26,7 @@ def prepare_pyqt4():
2626
pyside_found = False
2727
try:
2828
import PySide
29-
if V(PySide.__version__) < V('1.0.3'):
29+
if not check_version(PySide.__version__, '1.0.3'):
3030
# old PySide, fallback on PyQt
3131
raise ImportError
3232
# we can't import an incomplete pyside and pyqt4
@@ -49,7 +49,7 @@ def prepare_pyqt4():
4949
"present.\nThis will likely crash, please install " \
5050
"PySide completely, remove PySide or PyQt4 or set " \
5151
"the QT_API environment variable to pyqt or pyside"
52-
if V(QtCore.PYQT_VERSION_STR) < V('4.7'):
52+
if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
5353
# PyQt 4.6 has issues with null strings returning as None
5454
raise ImportError
5555
QT_API = QT_API_PYQT
@@ -63,7 +63,7 @@ def prepare_pyqt4():
6363
# Now peform the imports.
6464
if QT_API == QT_API_PYQT:
6565
from PyQt4 import QtCore, QtGui, QtSvg
66-
if V(QtCore.PYQT_VERSION_STR) < V('4.7'):
66+
if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
6767
raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
6868

6969
# Alias PyQt-specific functions for PySide compatibility.
@@ -72,7 +72,7 @@ def prepare_pyqt4():
7272

7373
elif QT_API == QT_API_PYSIDE:
7474
import PySide
75-
if V(PySide.__version__) < V('1.0.3'):
75+
if not check_version(PySide.__version__, '1.0.3'):
7676
raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
7777
from PySide import QtCore, QtGui, QtSvg
7878

IPython/external/qt_for_kernel.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
import sys
3333

3434
from IPython.utils.warn import warn
35-
from IPython.utils.version import NumericalVersion as V
35+
from IPython.utils.version import check_version
3636

3737
matplotlib = sys.modules.get('matplotlib')
38-
if matplotlib and V(matplotlib.__version__) <= V('1.0.1'):
38+
if matplotlib and not check_version(matplotlib.__version__, '1.0.2'):
3939
# 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
4040
# and ignore everything else
4141
from PyQt4 import QtCore, QtGui

IPython/utils/version.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,17 @@ def version_tuple(vs):
5353
regular integer element.
5454
"""
5555
return tuple(NumericalVersion(vs).version)
56+
57+
#
58+
def check_version(v, check):
59+
"""check version string v >= check
60+
61+
If dev/prerelease tags result in TypeError for string-number comparison,
62+
it is assumed that the dependency is satisfied.
63+
Users on dev branches are responsible for keeping their own packages up to date.
64+
"""
65+
try:
66+
return LooseVersion(v) >= LooseVersion(check)
67+
except TypeError:
68+
return True
5669

0 commit comments

Comments
 (0)