Skip to content

Commit 8e149ff

Browse files
miss-islingtonzooba
andcommitted
bpo-32409: Ensures activate.bat can handle Unicode contents (GH-5766)
(cherry picked from commit 6240917) Co-authored-by: Steve Dower <[email protected]>
1 parent ef0bb5c commit 8e149ff

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

Lib/test/test_venv.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,24 @@ def test_executable_symlinks(self):
286286
out, err = p.communicate()
287287
self.assertEqual(out.strip(), envpy.encode())
288288

289+
@unittest.skipUnless(os.name == 'nt', 'only relevant on Windows')
290+
def test_unicode_in_batch_file(self):
291+
"""
292+
Test isolation from system site-packages
293+
"""
294+
rmtree(self.env_dir)
295+
env_dir = os.path.join(os.path.realpath(self.env_dir), 'ϼўТλФЙ')
296+
builder = venv.EnvBuilder(clear=True)
297+
builder.create(env_dir)
298+
activate = os.path.join(env_dir, self.bindir, 'activate.bat')
299+
envpy = os.path.join(env_dir, self.bindir, self.exe)
300+
cmd = [activate, '&', self.exe, '-c', 'print(0)']
301+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE,
302+
stderr=subprocess.PIPE, encoding='oem',
303+
shell=True)
304+
out, err = p.communicate()
305+
print(err)
306+
self.assertEqual(out.strip(), '0')
289307

290308
@skipInVenv
291309
class EnsurePipTest(BaseTest):

Lib/venv/scripts/nt/activate.bat

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
@echo off
2+
3+
rem This file is UTF-8 encoded, so we need to update the current code page while executing it
4+
for /f "tokens=2 delims=:" %%a in ('"%SystemRoot%\System32\chcp.com"') do (
5+
set "_OLD_CODEPAGE=%%a"
6+
)
7+
if defined _OLD_CODEPAGE (
8+
"%SystemRoot%\System32\chcp.com" 65001 > nul
9+
)
10+
211
set "VIRTUAL_ENV=__VENV_DIR__"
312

413
if not defined PROMPT (
@@ -30,3 +39,7 @@ if defined _OLD_VIRTUAL_PATH (
3039
set "PATH=%VIRTUAL_ENV%\__VENV_BIN_NAME__;%PATH%"
3140

3241
:END
42+
if defined _OLD_CODEPAGE (
43+
"%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul
44+
set "_OLD_CODEPAGE="
45+
)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Ensures activate.bat can handle Unicode contents.

0 commit comments

Comments
 (0)