From 01f7891775f929e5fac2252246fc46396daec47c Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Wed, 3 Jan 2018 20:07:08 +1100 Subject: [PATCH 1/3] add safety wrapper around sys.stdout assignment --- tox/venv.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index 26bb42ae1..ccb578de3 100755 --- a/tox/venv.py +++ b/tox/venv.py @@ -302,10 +302,14 @@ def run_install_command(self, packages, action, options=()): os.environ.pop('PYTHONPATH') old_stdout = sys.stdout - sys.stdout = codecs.getwriter('utf8')(sys.stdout) - self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action, - redirect=self.session.report.verbosity < 2) - sys.stdout = old_stdout + try: + sys.stdout = codecs.getwriter('utf8')(sys.stdout) + self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action, + redirect=self.session.report.verbosity < 2) + except Exception: + raise + finally: + sys.stdout = old_stdout def _install(self, deps, extraopts=None, action=None): if not deps: From 69e05ace256edecce1f6d57b10f7076ac136472d Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Wed, 3 Jan 2018 20:07:08 +1100 Subject: [PATCH 2/3] add safety wrapper around sys.stdout assignment See #723 for bug details --- tox/venv.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tox/venv.py b/tox/venv.py index 26bb42ae1..3b3ecb32d 100755 --- a/tox/venv.py +++ b/tox/venv.py @@ -303,9 +303,11 @@ def run_install_command(self, packages, action, options=()): old_stdout = sys.stdout sys.stdout = codecs.getwriter('utf8')(sys.stdout) - self._pcall(argv, cwd=self.envconfig.config.toxinidir, action=action, - redirect=self.session.report.verbosity < 2) - sys.stdout = old_stdout + try: + self._pcall(argv, cwd=self.envconfig.config.toxinidir, + action=action, redirect=self.session.report.verbosity < 2) + finally: + sys.stdout = old_stdout def _install(self, deps, extraopts=None, action=None): if not deps: From b33d6d55a91f0eaa0ae40ab4d4290726668fa0e9 Mon Sep 17 00:00:00 2001 From: Anthony Shaw Date: Fri, 5 Jan 2018 10:58:01 +1100 Subject: [PATCH 3/3] add changelog reference to #723 --- changelog/723.bugfix.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 changelog/723.bugfix.rst diff --git a/changelog/723.bugfix.rst b/changelog/723.bugfix.rst new file mode 100644 index 000000000..8ec40c8e2 --- /dev/null +++ b/changelog/723.bugfix.rst @@ -0,0 +1,5 @@ +Fixed an issue where invocation of Tox from the Python package, where +invocation errors (failed actions) occur results in a change in the +sys.stdout stream encoding in Python 3.x. +New behaviour is that sys.stdout is reset back to its original encoding +after invocation errors - by @tonybaloney