Permalink
Browse files

Merge pull request #2831 from minrk/qtversions

avoid string version comparisons in external.qt
  • Loading branch information...
2 parents e8e6d48 + ab1ae26 commit 8f7490775a79220641c59489c05e2aba0da2c293 @takluyver takluyver committed Jan 28, 2013
Showing with 43 additions and 6 deletions.
  1. +5 −5 IPython/external/qt.py
  2. +2 −1 IPython/external/qt_for_kernel.py
  3. +36 −0 IPython/utils/version.py
View
@@ -7,7 +7,7 @@
"""
import os
-
+from IPython.utils.version import check_version
# Available APIs.
QT_API_PYQT = 'pyqt'
QT_API_PYSIDE = 'pyside'
@@ -26,7 +26,7 @@ def prepare_pyqt4():
pyside_found = False
try:
import PySide
- if PySide.__version__ < '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 @@ def prepare_pyqt4():
"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 QtCore.PYQT_VERSION_STR < '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 @@ def prepare_pyqt4():
# Now peform the imports.
if QT_API == QT_API_PYQT:
from PyQt4 import QtCore, QtGui, QtSvg
- if QtCore.PYQT_VERSION_STR < '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 @@ def prepare_pyqt4():
elif QT_API == QT_API_PYSIDE:
import PySide
- if PySide.__version__ < '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
@@ -32,9 +32,10 @@
import sys
from IPython.utils.warn import warn
+from IPython.utils.version import check_version
matplotlib = sys.modules.get('matplotlib')
-if matplotlib and matplotlib.__version__ <= '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
View
@@ -0,0 +1,36 @@
+# encoding: utf-8
+"""
+Utilities for version comparison
+
+It is a bit ridiculous that we need these.
+"""
+
+#-----------------------------------------------------------------------------
+# Copyright (C) 2013 The IPython Development Team
+#
+# Distributed under the terms of the BSD License. The full license is in
+# the file COPYING, distributed as part of this software.
+#-----------------------------------------------------------------------------
+
+#-----------------------------------------------------------------------------
+# Imports
+#-----------------------------------------------------------------------------
+
+from distutils.version import LooseVersion
+
+#-----------------------------------------------------------------------------
+# Code
+#-----------------------------------------------------------------------------
+
+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
+

0 comments on commit 8f74907

Please sign in to comment.