##// END OF EJS Templates
Backport PR #2831: avoid string version comparisons in external.qt...
MinRK -
Show More
@@ -0,0 +1,35 b''
1 # encoding: utf-8
2 """
3 Utilities for version comparison
4
5 It is a bit ridiculous that we need these.
6 """
7
8 #-----------------------------------------------------------------------------
9 # Copyright (C) 2013 The IPython Development Team
10 #
11 # Distributed under the terms of the BSD License. The full license is in
12 # the file COPYING, distributed as part of this software.
13 #-----------------------------------------------------------------------------
14
15 #-----------------------------------------------------------------------------
16 # Imports
17 #-----------------------------------------------------------------------------
18
19 from distutils.version import LooseVersion
20
21 #-----------------------------------------------------------------------------
22 # Code
23 #-----------------------------------------------------------------------------
24
25 def check_version(v, check):
26 """check version string v >= check
27
28 If dev/prerelease tags result in TypeError for string-number comparison,
29 it is assumed that the dependency is satisfied.
30 Users on dev branches are responsible for keeping their own packages up to date.
31 """
32 try:
33 return LooseVersion(v) >= LooseVersion(check)
34 except TypeError:
35 return True
@@ -7,7 +7,7 b' Do not use this if you need PyQt with the old QString/QVariant API.'
7 7 """
8 8
9 9 import os
10
10 from IPython.utils.version import check_version
11 11 # Available APIs.
12 12 QT_API_PYQT = 'pyqt'
13 13 QT_API_PYSIDE = 'pyside'
@@ -26,7 +26,7 b' if QT_API is None:'
26 26 pyside_found = False
27 27 try:
28 28 import PySide
29 if PySide.__version__ < '1.0.3':
29 if not check_version(PySide.__version__, '1.0.3'):
30 30 # old PySide, fallback on PyQt
31 31 raise ImportError
32 32 # we can't import an incomplete pyside and pyqt4
@@ -49,7 +49,7 b' if QT_API is None:'
49 49 "present.\nThis will likely crash, please install " \
50 50 "PySide completely, remove PySide or PyQt4 or set " \
51 51 "the QT_API environment variable to pyqt or pyside"
52 if QtCore.PYQT_VERSION_STR < '4.7':
52 if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
53 53 # PyQt 4.6 has issues with null strings returning as None
54 54 raise ImportError
55 55 QT_API = QT_API_PYQT
@@ -63,7 +63,7 b' elif QT_API == QT_API_PYQT:'
63 63 # Now peform the imports.
64 64 if QT_API == QT_API_PYQT:
65 65 from PyQt4 import QtCore, QtGui, QtSvg
66 if QtCore.PYQT_VERSION_STR < '4.7':
66 if not check_version(QtCore.PYQT_VERSION_STR, '4.7'):
67 67 raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
68 68
69 69 # Alias PyQt-specific functions for PySide compatibility.
@@ -72,7 +72,7 b' if QT_API == QT_API_PYQT:'
72 72
73 73 elif QT_API == QT_API_PYSIDE:
74 74 import PySide
75 if PySide.__version__ < '1.0.3':
75 if not check_version(PySide.__version__, '1.0.3'):
76 76 raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
77 77 from PySide import QtCore, QtGui, QtSvg
78 78
@@ -32,9 +32,10 b' import os'
32 32 import sys
33 33
34 34 from IPython.utils.warn import warn
35 from IPython.utils.version import check_version
35 36
36 37 matplotlib = sys.modules.get('matplotlib')
37 if matplotlib and matplotlib.__version__ <= '1.0.1':
38 if matplotlib and not check_version(matplotlib.__version__, '1.0.2'):
38 39 # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
39 40 # and ignore everything else
40 41 from PyQt4 import QtCore, QtGui
General Comments 0
You need to be logged in to leave comments. Login now