| 
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.4.x'  | 
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.  | 
@@ -189,14 +198,10 @@ def byte2str(b): return b  | 
189 | 198 | 
 
  | 
190 | 199 | 
 
  | 
191 | 200 | import numpy  | 
192 |  | -from distutils import version  | 
193 |  | -expected_version = version.LooseVersion(__version__numpy__)  | 
194 |  | -found_version = version.LooseVersion(numpy.__version__)  | 
195 |  | -if not found_version >= expected_version:  | 
 | 201 | +if not compare_versions(numpy.__version__, __version__numpy__):  | 
196 | 202 |     raise ImportError(  | 
197 | 203 |         'numpy %s or later is required; you have %s' % (  | 
198 | 204 |             __version__numpy__, numpy.__version__))  | 
199 |  | -del version  | 
200 | 205 | 
 
  | 
201 | 206 | 
 
  | 
202 | 207 | def _is_writable_dir(p):  | 
@@ -396,15 +401,6 @@ def checkdep_xmllint():  | 
396 | 401 |     except (IndexError, ValueError, UnboundLocalError, OSError):  | 
397 | 402 |         return None  | 
398 | 403 | 
 
  | 
399 |  | -def compare_versions(a, b):  | 
400 |  | -    "return True if a is greater than or equal to b"  | 
401 |  | -    if a:  | 
402 |  | -        a = distutils.version.LooseVersion(a)  | 
403 |  | -        b = distutils.version.LooseVersion(b)  | 
404 |  | -        if a>=b: return True  | 
405 |  | -        else: return False  | 
406 |  | -    else: return False  | 
407 |  | - | 
408 | 404 | def checkdep_ps_distiller(s):  | 
409 | 405 |     if not s:  | 
410 | 406 |         return False  | 
 | 
0 commit comments