From a2b007cf54da2e00325f23722da37b5ef91a0880 Mon Sep 17 00:00:00 2001 From: Anthony Kim <62267334+anthonykim1@users.noreply.github.com> Date: Fri, 15 Nov 2024 01:04:57 -0800 Subject: [PATCH] disable python shell integration for wsl (#24446) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Resolves: https://github.com/microsoft/vscode-python/issues/23829 From testing: ![Screenshot 2024-11-14 at 11 54 44 PM](https://github.com/user-attachments/assets/18bb29a8-7fca-4989-b4e9-5796d9632151) --- python_files/pythonrc.py | 4 +++- python_files/tests/test_shell_integration.py | 7 +++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python_files/pythonrc.py b/python_files/pythonrc.py index 5791bb3967c0..13f374e023b8 100644 --- a/python_files/pythonrc.py +++ b/python_files/pythonrc.py @@ -1,3 +1,4 @@ +import platform import sys if sys.platform != "win32": @@ -5,6 +6,7 @@ original_ps1 = ">>> " use_shell_integration = sys.version_info < (3, 13) +is_wsl = "microsoft-standard-WSL" in platform.release() class REPLHooks: @@ -73,5 +75,5 @@ def __str__(self): return result -if sys.platform != "win32" and use_shell_integration: +if sys.platform != "win32" and (not is_wsl) and use_shell_integration: sys.ps1 = PS1() diff --git a/python_files/tests/test_shell_integration.py b/python_files/tests/test_shell_integration.py index ea7ea4099bb2..a7dfc2ff1a8f 100644 --- a/python_files/tests/test_shell_integration.py +++ b/python_files/tests/test_shell_integration.py @@ -1,9 +1,12 @@ import importlib +import platform import sys from unittest.mock import Mock import pythonrc +is_wsl = "microsoft-standard-WSL" in platform.release() + def test_decoration_success(): importlib.reload(pythonrc) @@ -11,7 +14,7 @@ def test_decoration_success(): ps1.hooks.failure_flag = False result = str(ps1) - if sys.platform != "win32": + if sys.platform != "win32" and (not is_wsl): assert ( result == "\x1b]633;E;None\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" @@ -26,7 +29,7 @@ def test_decoration_failure(): ps1.hooks.failure_flag = True result = str(ps1) - if sys.platform != "win32": + if sys.platform != "win32" and (not is_wsl): assert ( result == "\x1b]633;E;None\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"