Commit 4b432e0f authored by Jason R. Coombs's avatar Jason R. Coombs

Issue 50: Removed filename and line number from SyntaxErrors returned by...

Issue 50: Removed filename and line number from SyntaxErrors returned by invalid_marker. This change simplifies the test and paves the way for supporting PyPy.
parent f3f0c144
......@@ -2,6 +2,16 @@
CHANGES
=======
---
1.0
---
* Issue #50: Normalized API of environment marker support. Specifically,
removed line number and filename from SyntaxErrors when returned from
`pkg_resources.invalid_marker`. Any clients depending on the specific
string representation of exceptions returned by that function may need to
be updated to account for this change.
-----
0.9.8
-----
......
......@@ -1267,12 +1267,22 @@ def _pyimp():
else:
return 'CPython'
def normalize_exception(exc):
"""
Given a SyntaxError from a marker evaluation, normalize the error message:
- Remove indications of filename and line number.
"""
exc.filename = None
exc.lineno = None
return exc
def invalid_marker(text):
"""Validate text as a PEP 426 environment marker; return exception or False"""
try:
evaluate_marker(text)
except SyntaxError:
return sys.exc_info()[1]
return normalize_exception(sys.exc_info()[1])
return False
def evaluate_marker(text, extra=None, _ops={}):
......
......@@ -341,8 +341,8 @@ Environment Markers
>>> print(im("sys_platform"))
Comparison or logical expression expected
>>> print(im("sys_platform==")) # doctest: +ELLIPSIS
unexpected EOF while parsing (...line 1)
>>> print(im("sys_platform=="))
unexpected EOF while parsing
>>> print(im("sys_platform=='win32'"))
False
......@@ -353,8 +353,8 @@ Environment Markers
>>> print(im("(extra)"))
Comparison or logical expression expected
>>> print(im("(extra")) # doctest: +ELLIPSIS
unexpected EOF while parsing (...line 1)
>>> print(im("(extra"))
unexpected EOF while parsing
>>> print(im("os.open('foo')=='y'"))
Language feature not supported in environment markers
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment