From 402b6907764baed9fcb2a94d480d2ab26168595b Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sat, 7 Feb 2015 16:40:14 -0700 Subject: [PATCH 1/3] Honor installed sys.excepthook in pex teardown. Previously an exception that bubbled from the underlying app was unconditionally printed. --- CHANGES.rst | 33 +++++++++++++++++++++++++++++++++ pex/pex.py | 8 ++++---- pex/version.py | 2 +- tests/test_pex.py | 18 ++++++++++++++++++ 4 files changed, 56 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3b2bf3a4c..3ee780de8 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -2,6 +2,39 @@ CHANGES ======= +---------- +0.8.6-rc.1 +---------- + +* Bug fix: Honor installed sys.excepthook in pex teardown. + `RB #XXX `_ + +----- +0.8.5 +----- + +* Bug fix: Fixup string formatting in pex/bin/pex.py to support Python 2.6 + `Pull Request #40 `_ + +----- +0.8.4 +----- + +* Performance improvement: Speed up the best-case scenario of dependency resolution. + `RB #1685 `_ + +* Bug fix: Change from uuid4().get_hex() to uuid4().hex to maintain Python3 + compatibility of pex.common. + `Pull Request #39 `_ + +* Bug fix: Actually cache the results of translation. Previously bdist translations + would be created in a temporary directory even if a cache location was specified. + `RB #1666 `_ + +* Bug fix: Support all potential abi tag permutations when determining platform + compatibility. + `Pull Request #33 `_ + ----- 0.8.3 ----- diff --git a/pex/pex.py b/pex/pex.py index beec14277..139343628 100644 --- a/pex/pex.py +++ b/pex/pex.py @@ -6,7 +6,6 @@ import os import subprocess import sys -import traceback from contextlib import contextmanager from distutils import sysconfig from site import USER_SITE @@ -273,15 +272,16 @@ def execute(self, args=()): else: self.execute_interpreter() except Exception: - # Catch and print any exceptions before we tear things down in finally, then - # reraise so that the exit status is reflected correctly. - traceback.print_exc() + # Allow the current sys.excepthook to handle this app exception before we tear things down in + # finally, then reraise so that the exit status is reflected correctly. + sys.excepthook(*sys.exc_info()) raise finally: # squash all exceptions on interpreter teardown -- the primary type here are # atexit handlers failing to run because of things such as: # http://stackoverflow.com/questions/2572172/referencing-other-modules-in-atexit if 'PEX_TEARDOWN_VERBOSE' not in os.environ: + sys.stderr.flush() sys.stderr = DevNull() sys.excepthook = lambda *a, **kw: None diff --git a/pex/version.py b/pex/version.py index 73f831511..fa92d4429 100644 --- a/pex/version.py +++ b/pex/version.py @@ -1 +1 @@ -__version__ = '0.8.5' +__version__ = '0.8.6-rc.1' diff --git a/tests/test_pex.py b/tests/test_pex.py index ff48cfe82..c02303fd3 100644 --- a/tests/test_pex.py +++ b/tests/test_pex.py @@ -19,6 +19,24 @@ def test_pex_uncaught_exceptions(): assert rc == 1 +def test_excepthook_honored(): + body = textwrap.dedent(""" + import sys + + def excepthook(ex_type, ex, tb): + print('Custom hook called with: {}'.format(ex)) + sys.exit(42) + + sys.excepthook = excepthook + + raise Exception('This is an exception') + """) + + so, rc = run_simple_pex_test(body) + assert so == b'Custom hook called with: This is an exception\n', 'Standard out was: %s' % so + assert rc == 42 + + def test_pex_sys_exit_does_not_raise(): body = "import sys; sys.exit(2)" so, rc = run_simple_pex_test(body) From 3c4264eeccfcf4c0ac92b4a917212397d0fdcd68 Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sat, 7 Feb 2015 16:46:55 -0700 Subject: [PATCH 2/3] Update CHANGES.rst and fix Python 2.6 compat. Update CHANGES.rst with the RB ID. Fixup string formatting to be python2.6 compatible. --- CHANGES.rst | 2 +- tests/test_pex.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 3ee780de8..066a0e496 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -7,7 +7,7 @@ CHANGES ---------- * Bug fix: Honor installed sys.excepthook in pex teardown. - `RB #XXX `_ + `RB #1733 `_ ----- 0.8.5 diff --git a/tests/test_pex.py b/tests/test_pex.py index c02303fd3..b1a5692e3 100644 --- a/tests/test_pex.py +++ b/tests/test_pex.py @@ -24,7 +24,7 @@ def test_excepthook_honored(): import sys def excepthook(ex_type, ex, tb): - print('Custom hook called with: {}'.format(ex)) + print('Custom hook called with: {0}'.format(ex)) sys.exit(42) sys.excepthook = excepthook From 846541c50fe0efd6c4b67de679c51531545d7bfa Mon Sep 17 00:00:00 2001 From: John Sirois Date: Sat, 7 Feb 2015 16:50:45 -0700 Subject: [PATCH 3/3] Use a PEP440-friendly pre-release version. --- CHANGES.rst | 2 +- pex/version.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 066a0e496..21f8a3b6d 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -3,7 +3,7 @@ CHANGES ======= ---------- -0.8.6-rc.1 +0.8.6-dev0 ---------- * Bug fix: Honor installed sys.excepthook in pex teardown. diff --git a/pex/version.py b/pex/version.py index fa92d4429..95b4da687 100644 --- a/pex/version.py +++ b/pex/version.py @@ -1 +1 @@ -__version__ = '0.8.6-rc.1' +__version__ = '0.8.6-dev0'