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

Skip to content

Commit 07fec13

Browse files
committed
Merge pull request matplotlib#1 from mdboom/pyparsing-monkey-patch
Pyparsing monkey patch
2 parents a8d5f96 + 0f19fec commit 07fec13

File tree

4 files changed

+36
-8
lines changed

4 files changed

+36
-8
lines changed

.travis.yml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,7 @@ python:
77
- 3.3
88

99
install:
10-
- pip install -q --use-mirrors nose python-dateutil numpy pep8
11-
# This is a workaround to install the latest versions of pyparsing,
12-
# which are not yet available on PyPI
13-
- 'if [ ${TRAVIS_PYTHON_VERSION:0:1} == "3" ]; then pip -q install http://sourceforge.net/projects/pyparsing/files/pyparsing/pyparsing-2.0.0/pyparsing-2.0.0.tar.gz; fi'
14-
- 'if [ ${TRAVIS_PYTHON_VERSION:0:1} == "2" ]; then pip -q install http://sourceforge.net/projects/pyparsing/files/pyparsing/pyparsing-1.5.7/pyparsing-1.5.7.tar.gz; fi'
10+
- pip install -q --use-mirrors nose python-dateutil numpy pep8 pyparsing
1511
- if [[ $TRAVIS_PYTHON_VERSION == '2.'* ]]; then pip -q install --use-mirrors PIL; fi
1612
- sudo apt-get update && sudo apt-get -qq install inkscape
1713
- python setup.py install

lib/matplotlib/__init__.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,21 @@
120120
"matplotlib requires pyparsing >= {0}".format(
121121
'.'.join(str(x) for x in _required)))
122122

123+
if pyparsing.__version__ == '2.0.0':
124+
raise ImportError(
125+
"pyparsing 2.0.0 has bugs that prevent its use with "
126+
"matplotlib")
127+
128+
# pyparsing 1.5.6 does not have <<= on the Forward class, but
129+
# 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__'):
133+
def _forward_ilshift(self, other):
134+
self.__lshift__(other)
135+
return self
136+
pyparsing.Forward.__ilshift__ = _forward_ilshift
137+
123138
import os, re, shutil, warnings
124139
import distutils.sysconfig
125140
import distutils.version

lib/matplotlib/mathtext.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,14 @@
4040
ParseResults, Suppress, oneOf, StringEnd, ParseFatalException, \
4141
FollowedBy, Regex, ParserElement, QuotedString, ParseBaseException
4242

43-
ParserElement.enablePackrat()
43+
# Enable packrat parsing
44+
if (sys.version_info[0] >= 3 and
45+
[int(x) for x in pyparsing.__version__.split('.')] < [2, 0, 0]):
46+
warn("Due to a bug in pyparsing <= 2.0.0 on Python 3.x, packrat parsing "
47+
"has been disabled. Mathtext rendering will be much slower as a "
48+
"result. Install pyparsing 2.0.0 or later to improve performance.")
49+
else:
50+
ParserElement.enablePackrat()
4451

4552
from matplotlib.afm import AFM
4653
from matplotlib.cbook import Bunch, get_realpath_and_stat, \

setupext.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -971,15 +971,25 @@ def check(self):
971971
"support. pip/easy_install may attempt to install it "
972972
"after matplotlib.")
973973

974-
required = [2, 0, 1]
974+
required = [1, 5, 6]
975975
if [int(x) for x in pyparsing.__version__.split('.')] < required:
976976
return (
977977
"matplotlib requires pyparsing >= {0}".format(
978978
'.'.join(str(x) for x in required)))
979+
980+
if pyparsing.__version__ == "2.0.0":
981+
if sys.version_info[0] == 2:
982+
return (
983+
"pyparsing 2.0.0 is not compatible with Python 2.x")
984+
else:
985+
return (
986+
"pyparsing 2.0.0 has bugs that prevent its use with "
987+
"matplotlib")
988+
979989
return "using pyparsing version %s" % pyparsing.__version__
980990

981991
def get_install_requires(self):
982-
return ['pyparsing>=2.0.1']
992+
return ['pyparsing>=1.5.6,!=2.0.0']
983993

984994

985995
class BackendAgg(OptionalBackendPackage):

0 commit comments

Comments
 (0)