Skip to content

Commit

Permalink
disable python shell integration for wsl (#24446)
Browse files Browse the repository at this point in the history
Resolves: #23829

From testing:
![Screenshot 2024-11-14 at 11 54
44 PM](https://github.com/user-attachments/assets/18bb29a8-7fca-4989-b4e9-5796d9632151)
  • Loading branch information
anthonykim1 authored Nov 15, 2024
1 parent 29d4f35 commit a2b007c
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
4 changes: 3 additions & 1 deletion python_files/pythonrc.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import platform
import sys

if sys.platform != "win32":
import readline

original_ps1 = ">>> "
use_shell_integration = sys.version_info < (3, 13)
is_wsl = "microsoft-standard-WSL" in platform.release()


class REPLHooks:
Expand Down Expand Up @@ -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()
7 changes: 5 additions & 2 deletions python_files/tests/test_shell_integration.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
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)
ps1 = pythonrc.PS1()

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"
Expand All @@ -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"
Expand Down

0 comments on commit a2b007c

Please sign in to comment.