Skip to content

Commit

Permalink
Merge pull request #2279 from jenshnielsen/pyparsing
Browse files Browse the repository at this point in the history
Pyparsing
  • Loading branch information
mdboom committed Aug 12, 2013
2 parents 87d25ff + 07fec13 commit 04b9ab9
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 68 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,7 @@ python:
- 3.3

install:
- pip install -q --use-mirrors nose python-dateutil numpy pep8
# This is a workaround to install the latest versions of pyparsing,
# which are not yet available on PyPI
- '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'
- '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'
- pip install -q --use-mirrors nose python-dateutil numpy pep8 pyparsing
- if [[ $TRAVIS_PYTHON_VERSION == '2.'* ]]; then pip -q install --use-mirrors PIL; fi
- sudo apt-get update && sudo apt-get -qq install inkscape
- python setup.py install
Expand Down
15 changes: 15 additions & 0 deletions lib/matplotlib/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,21 @@
"matplotlib requires pyparsing >= {0}".format(
'.'.join(str(x) for x in _required)))

if pyparsing.__version__ == '2.0.0':
raise ImportError(
"pyparsing 2.0.0 has bugs that prevent its use with "
"matplotlib")

# 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
90 changes: 45 additions & 45 deletions lib/matplotlib/mathtext.py
Original file line number Diff line number Diff line change
Expand Up @@ -2179,69 +2179,69 @@ def __init__(self):
if key != 'self':
val.setName(key)

float_literal << Regex(r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)")
int_literal << Regex("[-+]?[0-9]+")
float_literal <<= Regex(r"[-+]?([0-9]+\.?[0-9]*|\.[0-9]+)")
int_literal <<= Regex("[-+]?[0-9]+")

lbrace << Literal('{').suppress()
rbrace << Literal('}').suppress()
lbracket << Literal('[').suppress()
rbracket << Literal(']').suppress()
bslash << Literal('\\')
lbrace <<= Literal('{').suppress()
rbrace <<= Literal('}').suppress()
lbracket <<= Literal('[').suppress()
rbracket <<= Literal(']').suppress()
bslash <<= Literal('\\')

space << oneOf(self._space_widths.keys())
customspace << (Suppress(Literal(r'\hspace'))
space <<= oneOf(self._space_widths.keys())
customspace <<= (Suppress(Literal(r'\hspace'))
- ((lbrace + float_literal + rbrace)
| Error(r"Expected \hspace{n}")))

unicode_range = u"\U00000080-\U0001ffff"
single_symbol << Regex(UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
single_symbol <<= Regex(UR"([a-zA-Z0-9 +\-*/<>=:,.;!\?&'@()\[\]|%s])|(\\[%%${}\[\]_|])" %
unicode_range)
symbol_name << (Combine(bslash + oneOf(tex2uni.keys())) +
symbol_name <<= (Combine(bslash + oneOf(tex2uni.keys())) +
FollowedBy(Regex("[^A-Za-z]").leaveWhitespace() | StringEnd()))
symbol << (single_symbol | symbol_name).leaveWhitespace()
symbol <<= (single_symbol | symbol_name).leaveWhitespace()

apostrophe << Regex("'+")
apostrophe <<= Regex("'+")

c_over_c << Suppress(bslash) + oneOf(self._char_over_chars.keys())
c_over_c <<= Suppress(bslash) + oneOf(self._char_over_chars.keys())

accent << Group(
accent <<= Group(
Suppress(bslash)
+ oneOf(self._accent_map.keys() + list(self._wide_accents))
- placeable
)

function << Suppress(bslash) + oneOf(list(self._function_names))
function <<= Suppress(bslash) + oneOf(list(self._function_names))

start_group << Optional(latexfont) + lbrace
end_group << rbrace.copy()
simple_group << Group(lbrace + ZeroOrMore(token) + rbrace)
required_group<< Group(lbrace + OneOrMore(token) + rbrace)
group << Group(start_group + ZeroOrMore(token) + end_group)
start_group <<= Optional(latexfont) + lbrace
end_group <<= rbrace.copy()
simple_group <<= Group(lbrace + ZeroOrMore(token) + rbrace)
required_group<<= Group(lbrace + OneOrMore(token) + rbrace)
group <<= Group(start_group + ZeroOrMore(token) + end_group)

font << Suppress(bslash) + oneOf(list(self._fontnames))
latexfont << Suppress(bslash) + oneOf(['math' + x for x in self._fontnames])
font <<= Suppress(bslash) + oneOf(list(self._fontnames))
latexfont <<= Suppress(bslash) + oneOf(['math' + x for x in self._fontnames])

frac << Group(
frac <<= Group(
Suppress(Literal(r"\frac"))
- ((required_group + required_group) | Error(r"Expected \frac{num}{den}"))
)

stackrel << Group(
stackrel <<= Group(
Suppress(Literal(r"\stackrel"))
- ((required_group + required_group) | Error(r"Expected \stackrel{num}{den}"))
)

binom << Group(
binom <<= Group(
Suppress(Literal(r"\binom"))
- ((required_group + required_group) | Error(r"Expected \binom{num}{den}"))
)

ambi_delim << oneOf(list(self._ambi_delim))
left_delim << oneOf(list(self._left_delim))
right_delim << oneOf(list(self._right_delim))
right_delim_safe << oneOf(list(self._right_delim - set(['}'])) + [r'\}'])
ambi_delim <<= oneOf(list(self._ambi_delim))
left_delim <<= oneOf(list(self._left_delim))
right_delim <<= oneOf(list(self._right_delim))
right_delim_safe <<= oneOf(list(self._right_delim - set(['}'])) + [r'\}'])

genfrac << Group(
genfrac <<= Group(
Suppress(Literal(r"\genfrac"))
- (((lbrace + Optional(ambi_delim | left_delim, default='') + rbrace)
+ (lbrace + Optional(ambi_delim | right_delim_safe, default='') + rbrace)
Expand All @@ -2250,27 +2250,27 @@ def __init__(self):
| Error(r"Expected \genfrac{ldelim}{rdelim}{rulesize}{style}{num}{den}"))
)

sqrt << Group(
sqrt <<= Group(
Suppress(Literal(r"\sqrt"))
- ((Optional(lbracket + int_literal + rbracket, default=None)
+ required_group)
| Error("Expected \sqrt{value}"))
)

overline << Group(
overline <<= Group(
Suppress(Literal(r"\overline"))
- (required_group | Error("Expected \overline{value}"))
)

unknown_symbol<< Combine(bslash + Regex("[A-Za-z]*"))
unknown_symbol<<= Combine(bslash + Regex("[A-Za-z]*"))

operatorname << Group(
operatorname <<= Group(
Suppress(Literal(r"\operatorname"))
- ((lbrace + ZeroOrMore(simple | unknown_symbol) + rbrace)
| Error("Expected \operatorname{value}"))
)

placeable << ( accent # Must be first
placeable <<= ( accent # Must be first
| symbol # Must be second
| c_over_c
| function
Expand All @@ -2284,39 +2284,39 @@ def __init__(self):
| operatorname
)

simple << ( space
simple <<= ( space
| customspace
| font
| subsuper
)

subsuperop << oneOf(["_", "^"])
subsuperop <<= oneOf(["_", "^"])

subsuper << Group(
subsuper <<= Group(
(Optional(placeable) + OneOrMore(subsuperop - placeable) + Optional(apostrophe))
| (placeable + Optional(apostrophe))
| apostrophe
)

token << ( simple
token <<= ( simple
| auto_delim
| unknown_symbol # Must be last
)

auto_delim << (Suppress(Literal(r"\left"))
auto_delim <<= (Suppress(Literal(r"\left"))
- ((left_delim | ambi_delim) | Error("Expected a delimiter"))
+ Group(ZeroOrMore(simple | auto_delim))
+ Suppress(Literal(r"\right"))
- ((right_delim | ambi_delim) | Error("Expected a delimiter"))
)

math << OneOrMore(token)
math <<= OneOrMore(token)

math_string << QuotedString('$', '\\', unquoteResults=False)
math_string <<= QuotedString('$', '\\', unquoteResults=False)

non_math << Regex(r"(?:(?:\\[$])|[^$])*").leaveWhitespace()
non_math <<= Regex(r"(?:(?:\\[$])|[^$])*").leaveWhitespace()

main << (non_math + ZeroOrMore(math_string + non_math)) + StringEnd()
main <<= (non_math + ZeroOrMore(math_string + non_math)) + StringEnd()

# Set actions
for key, val in locals().items():
Expand Down
31 changes: 13 additions & 18 deletions setupext.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,30 +970,25 @@ def check(self):
"support. pip/easy_install may attempt to install it "
"after matplotlib.")

if sys.version_info[0] >= 3:
required = [2, 0, 0]
if [int(x) for x in pyparsing.__version__.split('.')] < required:
return (
"matplotlib requires pyparsing >= {0} on Python 3.x".format(
'.'.join(str(x) for x in required)))
else:
required = [1, 5, 6]
if [int(x) for x in pyparsing.__version__.split('.')] < required:
return (
"matplotlib requires pyparsing >= {0} on Python 2.x".format(
'.'.join(str(x) for x in required)))
if pyparsing.__version__ == "2.0.0":
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 pyparsing.__version__ == "2.0.0":
if sys.version_info[0] == 2:
return (
"pyparsing 2.0.0 is not compatible with Python 2.x")
else:
return (
"pyparsing 2.0.0 has bugs that prevent its use with "
"matplotlib")

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

def get_install_requires(self):
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']
return ['pyparsing>=1.5.6,!=2.0.0']


class BackendAgg(OptionalBackendPackage):
Expand Down

0 comments on commit 04b9ab9

Please sign in to comment.