diff options
author | Jason R. Coombs <jaraco@jaraco.com> | 2013-08-09 22:45:59 -0400 |
---|---|---|
committer | Jason R. Coombs <jaraco@jaraco.com> | 2013-08-09 22:45:59 -0400 |
commit | 4b432e0f50e9f5871a2f7375b406be7258bfa22c (patch) | |
tree | b054a4b3502a8ab6a68feec89822644919d41483 | |
parent | f3f0c144dcfec41924e2e3eac3cbbaa81cb53819 (diff) | |
download | external_python_setuptools-4b432e0f50e9f5871a2f7375b406be7258bfa22c.tar.gz external_python_setuptools-4b432e0f50e9f5871a2f7375b406be7258bfa22c.tar.bz2 external_python_setuptools-4b432e0f50e9f5871a2f7375b406be7258bfa22c.zip |
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.
-rw-r--r-- | CHANGES.txt | 10 | ||||
-rw-r--r-- | pkg_resources.py | 12 | ||||
-rw-r--r-- | tests/api_tests.txt | 8 |
3 files changed, 25 insertions, 5 deletions
diff --git a/CHANGES.txt b/CHANGES.txt index b2729aac..d3c6f989 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -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 ----- diff --git a/pkg_resources.py b/pkg_resources.py index 36a0e6ed..7c3bdccd 100644 --- a/pkg_resources.py +++ b/pkg_resources.py @@ -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={}): diff --git a/tests/api_tests.txt b/tests/api_tests.txt index 86ca245d..38b762d2 100644 --- a/tests/api_tests.txt +++ b/tests/api_tests.txt @@ -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 |