|
100 | 100 | from __future__ import print_function, absolute_import |
101 | 101 |
|
102 | 102 | import sys |
| 103 | +import distutils.version |
103 | 104 |
|
104 | 105 | __version__ = '1.3.0' |
105 | 106 | __version__numpy__ = '1.5' # minimum required numpy version |
|
109 | 110 | except ImportError: |
110 | 111 | raise ImportError("matplotlib requires dateutil") |
111 | 112 |
|
| 113 | +def compare_versions(a, b): |
| 114 | + "return True if a is greater than or equal to b" |
| 115 | + if a: |
| 116 | + a = distutils.version.LooseVersion(a) |
| 117 | + b = distutils.version.LooseVersion(b) |
| 118 | + if a>=b: return True |
| 119 | + else: return False |
| 120 | + else: return False |
| 121 | + |
112 | 122 | try: |
113 | 123 | import pyparsing |
114 | 124 | except ImportError: |
115 | 125 | raise ImportError("matplotlib requires pyparsing") |
116 | 126 | else: |
117 | | - _required = [1, 5, 6] |
118 | | - if [int(x) for x in pyparsing.__version__.split('.')] < _required: |
| 127 | + if not compare_versions(pyparsing.__version__, '1.5.6'): |
119 | 128 | raise ImportError( |
120 | | - "matplotlib requires pyparsing >= {0}".format( |
121 | | - '.'.join(str(x) for x in _required))) |
| 129 | + "matplotlib requires pyparsing >= 1.5.6") |
122 | 130 |
|
123 | 131 | if pyparsing.__version__ == '2.0.0': |
124 | 132 | raise ImportError( |
|
127 | 135 |
|
128 | 136 | # pyparsing 1.5.6 does not have <<= on the Forward class, but |
129 | 137 | # pyparsing 2.0.0 and later will spew deprecation warnings if |
130 | | - # using << instead. In order to support pyparsing 1.5.6 and above |
131 | | - # with a common code base, this small monkey patch is applied. |
132 | | - if not hasattr(pyparsing.Forward, '__ilshift__'): |
| 138 | + # using << instead. Additionally, the <<= in pyparsing 1.5.7 is |
| 139 | + # broken, since it doesn't return self. In order to support |
| 140 | + # pyparsing 1.5.6 and above with a common code base, this small |
| 141 | + # monkey patch is applied. |
| 142 | + if not compare_versions(pyparsing.__version__, '2.0.1'): |
133 | 143 | def _forward_ilshift(self, other): |
134 | 144 | self.__lshift__(other) |
135 | 145 | return self |
136 | 146 | pyparsing.Forward.__ilshift__ = _forward_ilshift |
137 | 147 |
|
138 | 148 | import os, re, shutil, warnings |
139 | 149 | import distutils.sysconfig |
140 | | -import distutils.version |
141 | 150 |
|
142 | 151 | # cbook must import matplotlib only within function |
143 | 152 | # definitions, so it is safe to import from it here. |
@@ -195,14 +204,10 @@ def byte2str(b): return b |
195 | 204 |
|
196 | 205 |
|
197 | 206 | import numpy |
198 | | -from distutils import version |
199 | | -expected_version = version.LooseVersion(__version__numpy__) |
200 | | -found_version = version.LooseVersion(numpy.__version__) |
201 | | -if not found_version >= expected_version: |
| 207 | +if not compare_versions(numpy.__version__, __version__numpy__): |
202 | 208 | raise ImportError( |
203 | 209 | 'numpy %s or later is required; you have %s' % ( |
204 | 210 | __version__numpy__, numpy.__version__)) |
205 | | -del version |
206 | 211 |
|
207 | 212 |
|
208 | 213 | def _is_writable_dir(p): |
@@ -402,15 +407,6 @@ def checkdep_xmllint(): |
402 | 407 | except (IndexError, ValueError, UnboundLocalError, OSError): |
403 | 408 | return None |
404 | 409 |
|
405 | | -def compare_versions(a, b): |
406 | | - "return True if a is greater than or equal to b" |
407 | | - if a: |
408 | | - a = distutils.version.LooseVersion(a) |
409 | | - b = distutils.version.LooseVersion(b) |
410 | | - if a>=b: return True |
411 | | - else: return False |
412 | | - else: return False |
413 | | - |
414 | 410 | def checkdep_ps_distiller(s): |
415 | 411 | if not s: |
416 | 412 | return False |
|
0 commit comments