##// END OF EJS Templates
add check_version utility...
MinRK -
Show More
@@ -7,7 +7,7 b' Do not use this if you need PyQt with the old QString/QVariant API.'
7 """
7 """
8
8
9 import os
9 import os
10 from IPython.utils.version import NumericalVersion as V
10 from IPython.utils.version import check_version
11 # Available APIs.
11 # Available APIs.
12 QT_API_PYQT = 'pyqt'
12 QT_API_PYQT = 'pyqt'
13 QT_API_PYSIDE = 'pyside'
13 QT_API_PYSIDE = 'pyside'
@@ -26,7 +26,7 b' if QT_API is None:'
26 pyside_found = False
26 pyside_found = False
27 try:
27 try:
28 import PySide
28 import PySide
29 if V(PySide.__version__) < V('1.0.3'):
29 if not check_version(PySide.__version__, '1.0.3'):
30 # old PySide, fallback on PyQt
30 # old PySide, fallback on PyQt
31 raise ImportError
31 raise ImportError
32 # we can't import an incomplete pyside and pyqt4
32 # we can't import an incomplete pyside and pyqt4
@@ -49,7 +49,7 b' if QT_API is None:'
49 "present.\nThis will likely crash, please install " \
49 "present.\nThis will likely crash, please install " \
50 "PySide completely, remove PySide or PyQt4 or set " \
50 "PySide completely, remove PySide or PyQt4 or set " \
51 "the QT_API environment variable to pyqt or pyside"
51 "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'):
53 # PyQt 4.6 has issues with null strings returning as None
53 # PyQt 4.6 has issues with null strings returning as None
54 raise ImportError
54 raise ImportError
55 QT_API = QT_API_PYQT
55 QT_API = QT_API_PYQT
@@ -63,7 +63,7 b' elif QT_API == QT_API_PYQT:'
63 # Now peform the imports.
63 # Now peform the imports.
64 if QT_API == QT_API_PYQT:
64 if QT_API == QT_API_PYQT:
65 from PyQt4 import QtCore, QtGui, QtSvg
65 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'):
67 raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
67 raise ImportError("IPython requires PyQt4 >= 4.7, found %s"%QtCore.PYQT_VERSION_STR)
68
68
69 # Alias PyQt-specific functions for PySide compatibility.
69 # Alias PyQt-specific functions for PySide compatibility.
@@ -72,7 +72,7 b' if QT_API == QT_API_PYQT:'
72
72
73 elif QT_API == QT_API_PYSIDE:
73 elif QT_API == QT_API_PYSIDE:
74 import PySide
74 import PySide
75 if V(PySide.__version__) < V('1.0.3'):
75 if not check_version(PySide.__version__, '1.0.3'):
76 raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
76 raise ImportError("IPython requires PySide >= 1.0.3, found %s"%PySide.__version__)
77 from PySide import QtCore, QtGui, QtSvg
77 from PySide import QtCore, QtGui, QtSvg
78
78
@@ -32,10 +32,10 b' import os'
32 import sys
32 import sys
33
33
34 from IPython.utils.warn import warn
34 from IPython.utils.warn import warn
35 from IPython.utils.version import NumericalVersion as V
35 from IPython.utils.version import check_version
36
36
37 matplotlib = sys.modules.get('matplotlib')
37 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'):
39 # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
39 # 1.0.1 doesn't support pyside or v2, so stick with PyQt @v1,
40 # and ignore everything else
40 # and ignore everything else
41 from PyQt4 import QtCore, QtGui
41 from PyQt4 import QtCore, QtGui
@@ -53,4 +53,17 b' def version_tuple(vs):'
53 regular integer element.
53 regular integer element.
54 """
54 """
55 return tuple(NumericalVersion(vs).version)
55 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
56 No newline at end of file
69
General Comments 0
You need to be logged in to leave comments. Login now