From d7a56c24169691ad0eeccb8b02d143a67e959dd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Sun, 11 Sep 2022 01:36:54 +0300 Subject: [PATCH 1/5] Ensures activate.bat can handle Unicode contents --- src/virtualenv/activation/batch/activate.bat | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/virtualenv/activation/batch/activate.bat b/src/virtualenv/activation/batch/activate.bat index 816853c6b..103d4e855 100644 --- a/src/virtualenv/activation/batch/activate.bat +++ b/src/virtualenv/activation/batch/activate.bat @@ -1,3 +1,11 @@ +@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=__VIRTUAL_ENV__" @if defined _OLD_VIRTUAL_PROMPT ( @@ -35,3 +43,8 @@ :ENDIFVPATH2 @set "PATH=%VIRTUAL_ENV%\__BIN_NAME__;%PATH%" + +@if defined _OLD_CODEPAGE ( + "%SystemRoot%\System32\chcp.com" %_OLD_CODEPAGE% > nul + @set _OLD_CODEPAGE= +) From e970ffca84530dbf39febb1e2e999768a9021887 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Mon, 19 Sep 2022 20:37:17 +0300 Subject: [PATCH 2/5] Add changelog entry --- docs/changelog/2416.feature.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 docs/changelog/2416.feature.rst diff --git a/docs/changelog/2416.feature.rst b/docs/changelog/2416.feature.rst new file mode 100644 index 000000000..61e433beb --- /dev/null +++ b/docs/changelog/2416.feature.rst @@ -0,0 +1 @@ +Ensures activate.bat can handle Unicode contents - by :user:`OmerFI`. From 8cac3dd2d19e9e04cbdedcfb43fa6d6c69cf1c6d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Tue, 20 Sep 2022 22:17:03 +0300 Subject: [PATCH 3/5] We now don't need to change the character code page to 65001 in tests --- tests/unit/activation/test_batch.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/unit/activation/test_batch.py b/tests/unit/activation/test_batch.py index 1d951b227..77119ba97 100644 --- a/tests/unit/activation/test_batch.py +++ b/tests/unit/activation/test_batch.py @@ -21,8 +21,7 @@ def __init__(self, session): self.unix_line_ending = False def _get_test_lines(self, activate_script): - # for BATCH utf-8 support need change the character code page to 650001 - return ["@echo off", "", "chcp 65001 1>NUL"] + super()._get_test_lines(activate_script) + return ["@echo off", ""] + super()._get_test_lines(activate_script) def quote(self, s): """double quotes needs to be single, and single need to be double""" From a763d88a5eacbaba701e1a757439297f452f359c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Tue, 27 Sep 2022 15:29:28 +0300 Subject: [PATCH 4/5] Set code page utf8 and back to original in test lines --- tests/unit/activation/test_batch.py | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/tests/unit/activation/test_batch.py b/tests/unit/activation/test_batch.py index 77119ba97..856ce4dcd 100644 --- a/tests/unit/activation/test_batch.py +++ b/tests/unit/activation/test_batch.py @@ -20,8 +20,31 @@ def __init__(self, session): self.pydoc_call = f"call {self.pydoc_call}" self.unix_line_ending = False + def set_code_page_utf8(self): + return """ + 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 + ) + """.strip().splitlines() + + def unset_code_page_utf8(self): + return """ + if defined _OLD_CODEPAGE ( + "%SystemRoot%\\System32\\chcp.com" %_OLD_CODEPAGE% > nul + set _OLD_CODEPAGE= + ) + """.strip().splitlines() + def _get_test_lines(self, activate_script): - return ["@echo off", ""] + super()._get_test_lines(activate_script) + return ( + ["@echo off", ""] + + self.set_code_page_utf8() + + super()._get_test_lines(activate_script) + + self.unset_code_page_utf8() + ) def quote(self, s): """double quotes needs to be single, and single need to be double""" From 1dd1335a43e365ea42d49aa27fd17c083423fdd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=96mer=20Furkan=20=C4=B0=C5=9Fleyen?= <54645034+OmerFI@users.noreply.github.com> Date: Tue, 27 Sep 2022 15:36:17 +0300 Subject: [PATCH 5/5] Use utf-8 for windows too instead of ascii --- tests/conftest.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/conftest.py b/tests/conftest.py index 68924dc35..1bce07e4e 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -11,7 +11,7 @@ from virtualenv.app_data import AppDataDiskFolder from virtualenv.discovery.builtin import get_interpreter from virtualenv.discovery.py_info import PythonInfo -from virtualenv.info import IS_WIN, fs_supports_symlink +from virtualenv.info import fs_supports_symlink from virtualenv.report import LOGGER @@ -294,7 +294,7 @@ def is_inside_ci(): def special_char_name(): base = "e-$ Γ¨Ρ€Ρ‚πŸš’β™žδΈ­η‰‡-j" # workaround for pypy3 https://bitbucket.org/pypy/pypy/issues/3147/venv-non-ascii-support-windows - encoding = "ascii" if IS_WIN else sys.getfilesystemencoding() + encoding = sys.getfilesystemencoding() # let's not include characters that the file system cannot encode) result = "" for char in base: