[Python-checkins] bpo-32409: Ensures activate.bat can handle Unicode contents (GH-5757)
Steve Dower
webhook-mailer at python.org
Mon Feb 19 20:25:27 EST 2018
https://github.com/python/cpython/commit/6240917b773b52f8883387b9e3a5f327a4372068
commit: 6240917b773b52f8883387b9e3a5f327a4372068
branch: master
author: Steve Dower <steve.dower at microsoft.com>
committer: GitHub <noreply at github.com>
date: 2018-02-19T17:25:24-08:00
summary:
bpo-32409: Ensures activate.bat can handle Unicode contents (GH-5757)
files:
A Misc/NEWS.d/next/Windows/2018-02-19-10-00-57.bpo-32409.nocuDg.rst
M Lib/test/test_venv.py
M Lib/venv/scripts/nt/activate.bat
diff --git a/Lib/test/test_venv.py b/Lib/test/test_venv.py
index c55042677067..9cea87e2fefa 100644
--- a/Lib/test/test_venv.py
+++ b/Lib/test/test_venv.py
@@ -281,6 +281,24 @@ def test_executable_symlinks(self):
out, err = p.communicate()
self.assertEqual(out.strip(), envpy.encode())
+ @unittest.skipUnless(os.name == 'nt', 'only relevant on Windows')
+ def test_unicode_in_batch_file(self):
+ """
+ Test isolation from system site-packages
+ """
+ rmtree(self.env_dir)
+ env_dir = os.path.join(os.path.realpath(self.env_dir), 'ϼўТλФЙ')
+ builder = venv.EnvBuilder(clear=True)
+ builder.create(env_dir)
+ activate = os.path.join(env_dir, self.bindir, 'activate.bat')
+ envpy = os.path.join(env_dir, self.bindir, self.exe)
+ cmd = [activate, '&', self.exe, '-c', 'print(0)']
+ p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE, encoding='oem',
+ shell=True)
+ out, err = p.communicate()
+ print(err)
+ self.assertEqual(out.strip(), '0')
@skipInVenv
class EnsurePipTest(BaseTest):
diff --git a/Lib/venv/scripts/nt/activate.bat b/Lib/venv/scripts/nt/activate.bat
index d76ca1359627..126049f495fe 100644
--- a/Lib/venv/scripts/nt/activate.bat
+++ b/Lib/venv/scripts/nt/activate.bat
@@ -1,4 +1,13 @@
@echo off
+
+rem This file is UTF-8 encoded, so we need to update the current code page while executing it
+for /f "tokens=2 delims=:" %%a in ('"%SystemRoot%\System32\chcp.com"') do (
+ set "_OLD_CODEPAGE=%%a"
+)
+if defined _OLD_CODEPAGE (
+ "%SystemRoot%\System32\chcp.com" 65001 > nul
+)
+
set "VIRTUAL_ENV=__VENV_DIR__"
if not defined PROMPT (
@@ -30,3 +39,7 @@ if defined _OLD_VIRTUAL_PATH (
set "PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH%"
:END
+if defined _OLD_CODEPAGE (
+ "%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
+ set "_OLD_CODEPAGE="
+)
diff --git a/Misc/NEWS.d/next/Windows/2018-02-19-10-00-57.bpo-32409.nocuDg.rst b/Misc/NEWS.d/next/Windows/2018-02-19-10-00-57.bpo-32409.nocuDg.rst
new file mode 100644
index 000000000000..36251b0b4783
--- /dev/null
+++ b/Misc/NEWS.d/next/Windows/2018-02-19-10-00-57.bpo-32409.nocuDg.rst
@@ -0,0 +1 @@
+Ensures activate.bat can handle Unicode contents.
More information about the Python-checkins
mailing list