Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 42078bf

Browse files
committed
Merge pull request #2338 from mdboom/mathtext-pyparsing157-crash
issues with pyparsing 1.5.7 and python 2.7
2 parents 33ce775 + 04aa5b1 commit 42078bf

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

lib/matplotlib/__init__.py

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@
100100
from __future__ import print_function, absolute_import
101101

102102
import sys
103+
import distutils.version
103104

104105
__version__ = '1.3.0'
105106
__version__numpy__ = '1.5' # minimum required numpy version
@@ -109,16 +110,23 @@
109110
except ImportError:
110111
raise ImportError("matplotlib requires dateutil")
111112

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+
112122
try:
113123
import pyparsing
114124
except ImportError:
115125
raise ImportError("matplotlib requires pyparsing")
116126
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'):
119128
raise ImportError(
120-
"matplotlib requires pyparsing >= {0}".format(
121-
'.'.join(str(x) for x in _required)))
129+
"matplotlib requires pyparsing >= 1.5.6")
122130

123131
if pyparsing.__version__ == '2.0.0':
124132
raise ImportError(
@@ -127,17 +135,18 @@
127135

128136
# pyparsing 1.5.6 does not have <<= on the Forward class, but
129137
# 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'):
133143
def _forward_ilshift(self, other):
134144
self.__lshift__(other)
135145
return self
136146
pyparsing.Forward.__ilshift__ = _forward_ilshift
137147

138148
import os, re, shutil, warnings
139149
import distutils.sysconfig
140-
import distutils.version
141150

142151
# cbook must import matplotlib only within function
143152
# definitions, so it is safe to import from it here.
@@ -189,14 +198,10 @@ def byte2str(b): return b
189198

190199

191200
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__):
196202
raise ImportError(
197203
'numpy %s or later is required; you have %s' % (
198204
__version__numpy__, numpy.__version__))
199-
del version
200205

201206

202207
def _is_writable_dir(p):
@@ -396,15 +401,6 @@ def checkdep_xmllint():
396401
except (IndexError, ValueError, UnboundLocalError, OSError):
397402
return None
398403

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-
408404
def checkdep_ps_distiller(s):
409405
if not s:
410406
return False

0 commit comments

Comments
 (0)