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

Skip to content

Commit 5f8624d

Browse files
committed
Merge pull request #2380 from juliantaylor/pyparsing-check
check if pyparsing <<= is broken instead of checking the version
2 parents 0f8a452 + c075900 commit 5f8624d

File tree

2 files changed

+26
-14
lines changed

2 files changed

+26
-14
lines changed

lib/matplotlib/__init__.py

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -128,18 +128,21 @@ def compare_versions(a, b):
128128
raise ImportError(
129129
"matplotlib requires pyparsing >= 1.5.6")
130130

131-
if pyparsing.__version__ == '2.0.0':
132-
raise ImportError(
133-
"pyparsing 2.0.0 has bugs that prevent its use with "
134-
"matplotlib")
131+
# pyparsing 2.0.0 bug, but it may be patched in distributions
132+
try:
133+
f = pyparsing.Forward()
134+
f <<= pyparsing.Literal('a')
135+
bad_pyparsing = f is None
136+
except:
137+
bad_pyparsing = True
135138

136139
# pyparsing 1.5.6 does not have <<= on the Forward class, but
137140
# pyparsing 2.0.0 and later will spew deprecation warnings if
138141
# using << instead. Additionally, the <<= in pyparsing 1.5.7 is
139142
# broken, since it doesn't return self. In order to support
140143
# pyparsing 1.5.6 and above with a common code base, this small
141144
# monkey patch is applied.
142-
if not compare_versions(pyparsing.__version__, '2.0.1'):
145+
if bad_pyparsing:
143146
def _forward_ilshift(self, other):
144147
self.__lshift__(other)
145148
return self

setupext.py

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,16 @@ def get_install_requires(self):
949949
class Pyparsing(SetupPackage):
950950
name = "pyparsing"
951951

952+
def is_ok(self):
953+
# pyparsing 2.0.0 bug, but it may be patched in distributions
954+
try:
955+
import pyparsing
956+
f = pyparsing.Forward()
957+
f <<= pyparsing.Literal('a')
958+
return f is not None
959+
except:
960+
return False
961+
952962
def check(self):
953963
try:
954964
import pyparsing
@@ -964,19 +974,18 @@ def check(self):
964974
"matplotlib requires pyparsing >= {0}".format(
965975
'.'.join(str(x) for x in required)))
966976

967-
if pyparsing.__version__ == "2.0.0":
968-
if sys.version_info[0] == 2:
969-
return (
970-
"pyparsing 2.0.0 is not compatible with Python 2.x")
971-
else:
972-
return (
973-
"pyparsing 2.0.0 has bugs that prevent its use with "
974-
"matplotlib")
977+
if not self.is_ok():
978+
return (
979+
"pyparsing 2.0.0 has bugs that prevent its use with "
980+
"matplotlib")
975981

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

978984
def get_install_requires(self):
979-
return ['pyparsing>=1.5.6,!=2.0.0']
985+
if self.is_ok():
986+
return ['pyparsing>=1.5.6']
987+
else:
988+
return ['pyparsing>=1.5.6,!=2.0.0']
980989

981990

982991
class BackendAgg(OptionalBackendPackage):

0 commit comments

Comments
 (0)