changeset: 102073:15900c612ca7 branch: 3.5 parent: 102068:948652fb074d user: Steve Dower date: Fri Jun 17 09:32:38 2016 -0700 files: Lib/distutils/_msvccompiler.py Lib/distutils/tests/test_msvccompiler.py Misc/NEWS description: Issue #27048: Prevents distutils failing on Windows when environment variables contain non-ASCII characters diff -r 948652fb074d -r 15900c612ca7 Lib/distutils/_msvccompiler.py --- a/Lib/distutils/_msvccompiler.py Fri Jun 17 11:11:07 2016 +0300 +++ b/Lib/distutils/_msvccompiler.py Fri Jun 17 09:32:38 2016 -0700 @@ -86,11 +86,9 @@ try: out = subprocess.check_output( - '"{}" {} && set'.format(vcvarsall, plat_spec), - shell=True, + 'cmd /u /c "{}" {} && set'.format(vcvarsall, plat_spec), stderr=subprocess.STDOUT, - universal_newlines=True, - ) + ).decode('utf-16le', errors='replace') except subprocess.CalledProcessError as exc: log.error(exc.output) raise DistutilsPlatformError("Error executing {}" diff -r 948652fb074d -r 15900c612ca7 Lib/distutils/tests/test_msvccompiler.py --- a/Lib/distutils/tests/test_msvccompiler.py Fri Jun 17 11:11:07 2016 +0300 +++ b/Lib/distutils/tests/test_msvccompiler.py Fri Jun 17 09:32:38 2016 -0700 @@ -83,6 +83,24 @@ self.assertFalse(os.path.isfile(os.path.join( tempdir, os.path.basename(dll)))) + def test_get_vc_env_unicode(self): + import distutils._msvccompiler as _msvccompiler + + test_var = 'ṰḖṤṪ┅ṼẨṜ' + test_value = '₃⁴₅' + + # Ensure we don't early exit from _get_vc_env + old_distutils_use_sdk = os.environ.pop('DISTUTILS_USE_SDK', None) + os.environ[test_var] = test_value + try: + env = _msvccompiler._get_vc_env('x86') + self.assertIn(test_var.lower(), env) + self.assertEqual(test_value, env[test_var.lower()]) + finally: + os.environ.pop(test_var) + if old_distutils_use_sdk: + os.environ['DISTUTILS_USE_SDK'] = old_distutils_use_sdk + def test_suite(): return unittest.makeSuite(msvccompilerTestCase) diff -r 948652fb074d -r 15900c612ca7 Misc/NEWS --- a/Misc/NEWS Fri Jun 17 11:11:07 2016 +0300 +++ b/Misc/NEWS Fri Jun 17 09:32:38 2016 -0700 @@ -13,6 +13,9 @@ Library ------- +- Issue #27048: Prevents distutils failing on Windows when environment + variables contain non-ASCII characters + - Issue #27330: Fixed possible leaks in the ctypes module. - Issue #27238: Got rid of bare excepts in the turtle module. Original patch