From 04aa5b15d52dad5313be3324d23dea63aead3152 Mon Sep 17 00:00:00 2001 From: Michael Droettboom Date: Mon, 26 Aug 2013 11:39:26 -0400 Subject: [PATCH] Fix #2338: pyparsing in 1.5.7's <<= operator doesn't return self, so we need to monkey patch it, too --- lib/matplotlib/__init__.py | 40 +++++++++++++++++--------------------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/lib/matplotlib/__init__.py b/lib/matplotlib/__init__.py index 87f1c15e41e8..50e4448a7862 100644 --- a/lib/matplotlib/__init__.py +++ b/lib/matplotlib/__init__.py @@ -100,6 +100,7 @@ from __future__ import print_function, absolute_import import sys +import distutils.version __version__ = '1.3.0' __version__numpy__ = '1.5' # minimum required numpy version @@ -109,16 +110,23 @@ except ImportError: raise ImportError("matplotlib requires dateutil") +def compare_versions(a, b): + "return True if a is greater than or equal to b" + if a: + a = distutils.version.LooseVersion(a) + b = distutils.version.LooseVersion(b) + if a>=b: return True + else: return False + else: return False + try: import pyparsing except ImportError: raise ImportError("matplotlib requires pyparsing") else: - _required = [1, 5, 6] - if [int(x) for x in pyparsing.__version__.split('.')] < _required: + if not compare_versions(pyparsing.__version__, '1.5.6'): raise ImportError( - "matplotlib requires pyparsing >= {0}".format( - '.'.join(str(x) for x in _required))) + "matplotlib requires pyparsing >= 1.5.6") if pyparsing.__version__ == '2.0.0': raise ImportError( @@ -127,9 +135,11 @@ # pyparsing 1.5.6 does not have <<= on the Forward class, but # pyparsing 2.0.0 and later will spew deprecation warnings if - # using << instead. In order to support pyparsing 1.5.6 and above - # with a common code base, this small monkey patch is applied. - if not hasattr(pyparsing.Forward, '__ilshift__'): + # using << instead. Additionally, the <<= in pyparsing 1.5.7 is + # broken, since it doesn't return self. In order to support + # pyparsing 1.5.6 and above with a common code base, this small + # monkey patch is applied. + if not compare_versions(pyparsing.__version__, '2.0.1'): def _forward_ilshift(self, other): self.__lshift__(other) return self @@ -137,7 +147,6 @@ def _forward_ilshift(self, other): import os, re, shutil, warnings import distutils.sysconfig -import distutils.version # cbook must import matplotlib only within function # definitions, so it is safe to import from it here. @@ -195,14 +204,10 @@ def byte2str(b): return b import numpy -from distutils import version -expected_version = version.LooseVersion(__version__numpy__) -found_version = version.LooseVersion(numpy.__version__) -if not found_version >= expected_version: +if not compare_versions(numpy.__version__, __version__numpy__): raise ImportError( 'numpy %s or later is required; you have %s' % ( __version__numpy__, numpy.__version__)) -del version def _is_writable_dir(p): @@ -402,15 +407,6 @@ def checkdep_xmllint(): except (IndexError, ValueError, UnboundLocalError, OSError): return None -def compare_versions(a, b): - "return True if a is greater than or equal to b" - if a: - a = distutils.version.LooseVersion(a) - b = distutils.version.LooseVersion(b) - if a>=b: return True - else: return False - else: return False - def checkdep_ps_distiller(s): if not s: return False