Skip to content

Commit 5302d0e

Browse files
authored
Revert unsuccessful REPL decoration fix and disable for windows (#22578)
Reverting #22572 since it is producing color decoration on weird Python REPL spot for Windows pwsh users, and disable decoration entirely for Windows pwsh users temporarily while trying to fix specific problem. Disable feature for stable. Refer: #22546 #22535
1 parent bffc9b3 commit 5302d0e

File tree

2 files changed

+72
-78
lines changed

2 files changed

+72
-78
lines changed

pythonFiles/pythonrc.py

Lines changed: 41 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,55 @@
1-
import sys
1+
# import sys
22

3-
original_ps1 = ">>> "
3+
# original_ps1 = ">>> "
44

55

6-
class repl_hooks:
7-
def __init__(self):
8-
self.global_exit = None
9-
self.failure_flag = False
10-
self.original_excepthook = sys.excepthook
11-
self.original_displayhook = sys.displayhook
12-
sys.excepthook = self.my_excepthook
13-
sys.displayhook = self.my_displayhook
6+
# class repl_hooks:
7+
# def __init__(self):
8+
# self.global_exit = None
9+
# self.failure_flag = False
10+
# self.original_excepthook = sys.excepthook
11+
# self.original_displayhook = sys.displayhook
12+
# sys.excepthook = self.my_excepthook
13+
# sys.displayhook = self.my_displayhook
1414

15-
def my_displayhook(self, value):
16-
if value is None:
17-
self.failure_flag = False
15+
# def my_displayhook(self, value):
16+
# if value is None:
17+
# self.failure_flag = False
1818

19-
self.original_displayhook(value)
19+
# self.original_displayhook(value)
2020

21-
def my_excepthook(self, type, value, traceback):
22-
self.global_exit = value
23-
self.failure_flag = True
21+
# def my_excepthook(self, type, value, traceback):
22+
# self.global_exit = value
23+
# self.failure_flag = True
2424

25-
self.original_excepthook(type, value, traceback)
25+
# self.original_excepthook(type, value, traceback)
2626

2727

28-
class ps1:
29-
hooks = repl_hooks()
30-
sys.excepthook = hooks.my_excepthook
31-
sys.displayhook = hooks.my_displayhook
28+
# class ps1:
29+
# hooks = repl_hooks()
30+
# sys.excepthook = hooks.my_excepthook
31+
# sys.displayhook = hooks.my_displayhook
3232

33-
# str will get called for every prompt with exit code to show success/failure
34-
def __str__(self):
35-
exit_code = 0
36-
if self.hooks.failure_flag:
37-
exit_code = 1
38-
else:
39-
exit_code = 0
33+
# # str will get called for every prompt with exit code to show success/failure
34+
# def __str__(self):
35+
# exit_code = 0
36+
# if self.hooks.failure_flag:
37+
# exit_code = 1
38+
# else:
39+
# exit_code = 0
4040

41-
# Guide following official VS Code doc for shell integration sequence:
42-
result = "{command_explicit}{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(
43-
command_explicit="\x1b]633;E;\x07",
44-
command_finished="\x1b]633;D;" + str(exit_code) + "\x07",
45-
prompt_started="\x1b]633;A\x07",
46-
prompt=original_ps1,
47-
command_start="\x1b]633;B\x07",
48-
command_executed="\x1b]633;C\x07",
49-
)
50-
# result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}"
41+
# # Guide following official VS Code doc for shell integration sequence:
42+
# # result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format(
43+
# # command_finished="\x1b]633;D;" + str(exit_code) + "\x07",
44+
# # prompt_started="\x1b]633;A\x07",
45+
# # prompt=original_ps1,
46+
# # command_start="\x1b]633;B\x07",
47+
# # command_executed="\x1b]633;C\x07",
48+
# # )
49+
# result = f"{chr(27)}]633;D;{exit_code}{chr(7)}{chr(27)}]633;A{chr(7)}{original_ps1}{chr(27)}]633;B{chr(7)}{chr(27)}]633;C{chr(7)}"
5150

52-
return result
51+
# return result
5352

5453

55-
sys.ps1 = ps1()
54+
# if sys.platform != "win32":
55+
# sys.ps1 = ps1()
Lines changed: 31 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,48 @@
1-
import importlib
2-
from unittest.mock import Mock
1+
# import importlib
2+
# from unittest.mock import Mock
33

4-
import pythonrc
4+
# import pythonrc
55

66

7-
def test_decoration_success():
8-
importlib.reload(pythonrc)
9-
ps1 = pythonrc.ps1()
7+
# def test_decoration_success():
8+
# importlib.reload(pythonrc)
9+
# ps1 = pythonrc.ps1()
1010

11-
ps1.hooks.failure_flag = False
12-
result = str(ps1)
13-
assert (
14-
result
15-
== "\x1b]633;E;\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
16-
)
11+
# ps1.hooks.failure_flag = False
12+
# result = str(ps1)
13+
# assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
1714

1815

19-
def test_decoration_failure():
20-
importlib.reload(pythonrc)
21-
ps1 = pythonrc.ps1()
16+
# def test_decoration_failure():
17+
# importlib.reload(pythonrc)
18+
# ps1 = pythonrc.ps1()
2219

23-
ps1.hooks.failure_flag = True
24-
result = str(ps1)
20+
# ps1.hooks.failure_flag = True
21+
# result = str(ps1)
2522

26-
assert (
27-
result
28-
== "\x1b]633;E;\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
29-
)
23+
# assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07"
3024

3125

32-
def test_displayhook_call():
33-
importlib.reload(pythonrc)
34-
pythonrc.ps1()
35-
mock_displayhook = Mock()
26+
# def test_displayhook_call():
27+
# importlib.reload(pythonrc)
28+
# pythonrc.ps1()
29+
# mock_displayhook = Mock()
3630

37-
hooks = pythonrc.repl_hooks()
38-
hooks.original_displayhook = mock_displayhook
31+
# hooks = pythonrc.repl_hooks()
32+
# hooks.original_displayhook = mock_displayhook
3933

40-
hooks.my_displayhook("mock_value")
34+
# hooks.my_displayhook("mock_value")
4135

42-
mock_displayhook.assert_called_once_with("mock_value")
36+
# mock_displayhook.assert_called_once_with("mock_value")
4337

4438

45-
def test_excepthook_call():
46-
importlib.reload(pythonrc)
47-
pythonrc.ps1()
48-
mock_excepthook = Mock()
39+
# def test_excepthook_call():
40+
# importlib.reload(pythonrc)
41+
# pythonrc.ps1()
42+
# mock_excepthook = Mock()
4943

50-
hooks = pythonrc.repl_hooks()
51-
hooks.original_excepthook = mock_excepthook
44+
# hooks = pythonrc.repl_hooks()
45+
# hooks.original_excepthook = mock_excepthook
5246

53-
hooks.my_excepthook("mock_type", "mock_value", "mock_traceback")
54-
mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback")
47+
# hooks.my_excepthook("mock_type", "mock_value", "mock_traceback")
48+
# mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback")

0 commit comments

Comments
 (0)