From b6be263b1cca0886ed7cd736cd76c094a695ad11 2013-01-27 21:28:32 From: MinRK Date: 2013-01-27 21:28:32 Subject: [PATCH] add check_version utility using LooseVersion and explicitly catching TypeError, rather than the NumericalVersion subclass. --- diff --git a/IPython/external/qt.py b/IPython/external/qt.py index a20e594..bbeea0c 100644 --- a/IPython/external/qt.py +++ b/IPython/external/qt.py @@ -7,7 +7,7 @@ Do not use this if you need PyQt with the old QString/QVariant API. """ import os -from IPython.utils.version import NumericalVersion as V +from IPython.utils.version import check_version # Available APIs. QT_API_PYQT = 'pyqt' QT_API_PYSIDE = 'pyside' @@ -26,7 +26,7 @@ if QT_API is None: pyside_found = False try: import PySide - if V(PySide.__version__) < V('1.0.3'): + if not check_version(PySide.__version__, '1.0.3'): # old PySide, fallback on PyQt raise ImportError # we can't import an incomplete pyside and pyqt4 @@ -49,7 +49,7 @@ if QT_API is None: "present.\nThis will likely crash, please install " \ "PySide completely, remove PySide or PyQt4 or set " \ "the QT_API environment variable to pyqt or pyside" - if V(QtCore.PYQT_VERSION_STR) < V('4.7'): + if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): # PyQt 4.6 has issues with null strings returning as None raise ImportError QT_API = QT_API_PYQT @@ -63,7 +63,7 @@ elif QT_API == QT_API_PYQT: # Now peform the imports. if QT_API == QT_API_PYQT: from PyQt4 import QtCore, QtGui, QtSvg - if V(QtCore.PYQT_VERSION_STR) < V('4.7'): + if not check_version(QtCore.PYQT_VERSION_STR, '4.7'): raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR) # Alias PyQt-specific functions for PySide compatibility. @@ -72,7 +72,7 @@ if QT_API == QT_API_PYQT: elif QT_API == QT_API_PYSIDE: import PySide - if V(PySide.__version__) < V('1.0.3'): + if not check_version(PySide.__version__, '1.0.3'): raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__) from PySide import QtCore, QtGui, QtSvg diff --git a/IPython/external/qt_for_kernel.py b/IPython/external/qt_for_kernel.py index 2372cc3..2779de7 100644 --- a/IPython/external/qt_for_kernel.py +++ b/IPython/external/qt_for_kernel.py @@ -32,10 +32,10 @@ import os import sys from IPython.utils.warn import warn -from IPython.utils.version import NumericalVersion as V +from IPython.utils.version import check_version matplotlib = sys.modules.get('matplotlib') -if matplotlib and V(matplotlib.__version__) <= V('1.0.1'): +if matplotlib and not check_version(matplotlib.__version__, '1.0.2'): # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1, # and ignore everything else from PyQt4 import QtCore, QtGui diff --git a/IPython/utils/version.py b/IPython/utils/version.py index 867cab5..01b42c9 100644 --- a/IPython/utils/version.py +++ b/IPython/utils/version.py @@ -53,4 +53,17 @@ def version_tuple(vs): regular integer element. """ return tuple(NumericalVersion(vs).version) + +# +def check_version(v, check): + """check version string v >= check + + If dev/prerelease tags result in TypeError for string-number comparison, + it is assumed that the dependency is satisfied. + Users on dev branches are responsible for keeping their own packages up to date. + """ + try: + return LooseVersion(v) >= LooseVersion(check) + except TypeError: + return True \ No newline at end of file