diff options
| -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 |
