Skip to content

Commit a3d6c1b

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

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
@@ -281,6 +281,24 @@ def test_executable_symlinks(self):
281281
out, err = p.communicate()
282282
self.assertEqual(out.strip(), envpy.encode())
283283

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

285303
@skipInVenv
286304
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)