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

Skip to content

Pyparsing #2279

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 12, 2013
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Monkey patch pyparsing so that we can support pyparsing >= 1.5.6 on b…
…oth Python 2 and 3 without loads of deprecation warnings.
  • Loading branch information
mdboom committed Aug 7, 2013
commit 0fa8a9ae00d7b85f9cd5c7537eb8045c6adec427
10 changes: 10 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,16 @@
"matplotlib requires pyparsing >= {0}".format(
'.'.join(str(x) for x in _required)))

# 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__'):
def _forward_ilshift(self, other):
self.__lshift__(other)
return self
pyparsing.Forward.__ilshift__ = _forward_ilshift

import os, re, shutil, warnings
import distutils.sysconfig
import distutils.version
Expand Down
9 changes: 8 additions & 1 deletion lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,14 @@
ParseResults, Suppress, oneOf, StringEnd, ParseFatalException, \
FollowedBy, Regex, ParserElement, QuotedString, ParseBaseException

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

from matplotlib.afm import AFM
from matplotlib.cbook import Bunch, get_realpath_and_stat, \
Expand Down
14 changes: 12 additions & 2 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -971,15 +971,25 @@ def check(self):
"support. pip/easy_install may attempt to install it "
"after matplotlib.")

required = [2, 0, 1]
required = [1, 5, 6]
if [int(x) for x in pyparsing.__version__.split('.')] < required:
return (
"matplotlib requires pyparsing >= {0}".format(
'.'.join(str(x) for x in required)))

if sys.version_info[0] == 2:
if pyparsing.__version__ == "2.0.0":
return (
"pyparsing 2.0.0 is not compatible with Python 2.x")

return "using pyparsing version %s" % pyparsing.__version__

def get_install_requires(self):
return ['pyparsing>=2.0.1']
if sys.version_info[0] >= 3:
return ['pyparsing>=1.5.6']
else:
# pyparsing >= 2.0.0 is not compatible with Python 2
return ['pyparsing>=1.5.6,!=2.0.0']


class BackendAgg(OptionalBackendPackage):
Expand Down