From 07affbf0fbabc0fec36a3d7379ddcd3623a8a4af Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 30 Nov 2023 10:40:10 -0800 Subject: [PATCH 1/4] revert unsucessful repl dec fix and disable for windows --- pythonFiles/pythonrc.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 6cba53db3897..e17151324aad 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -39,8 +39,7 @@ def __str__(self): exit_code = 0 # Guide following official VS Code doc for shell integration sequence: - result = "{command_explicit}{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( - command_explicit="\x1b]633;E;\x07", + result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( command_finished="\x1b]633;D;" + str(exit_code) + "\x07", prompt_started="\x1b]633;A\x07", prompt=original_ps1, @@ -52,4 +51,5 @@ def __str__(self): return result -sys.ps1 = ps1() +if sys.platform != "win32": + sys.ps1 = ps1() From 20d1426f949e035cd4e90138d2d99337736517f0 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 30 Nov 2023 10:52:26 -0800 Subject: [PATCH 2/4] revert to original way --- pythonFiles/pythonrc.py | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index e17151324aad..616a59e21203 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -39,14 +39,14 @@ def __str__(self): exit_code = 0 # Guide following official VS Code doc for shell integration sequence: - result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( - command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - prompt_started="\x1b]633;A\x07", - prompt=original_ps1, - command_start="\x1b]633;B\x07", - command_executed="\x1b]633;C\x07", - ) - # 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)}" + # result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( + # command_finished="\x1b]633;D;" + str(exit_code) + "\x07", + # prompt_started="\x1b]633;A\x07", + # prompt=original_ps1, + # command_start="\x1b]633;B\x07", + # command_executed="\x1b]633;C\x07", + # ) + 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)}" return result From 6d495695750c654432cf5e6b87deeaa5b0ce8ef4 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 30 Nov 2023 10:54:02 -0800 Subject: [PATCH 3/4] fix tests --- pythonFiles/tests/test_shell_integration.py | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index ed3b9da916ac..06bb42499c58 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -10,10 +10,7 @@ def test_decoration_success(): ps1.hooks.failure_flag = False result = str(ps1) - assert ( - result - == "\x1b]633;E;\x07\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" - ) + assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" def test_decoration_failure(): @@ -23,10 +20,7 @@ def test_decoration_failure(): ps1.hooks.failure_flag = True result = str(ps1) - assert ( - result - == "\x1b]633;E;\x07\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" - ) + assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" def test_displayhook_call(): From 6d2017107572bf5ac4b88857401a1a29def05c47 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 30 Nov 2023 12:51:09 -0800 Subject: [PATCH 4/4] comment decoration feature for stable --- pythonFiles/pythonrc.py | 82 ++++++++++----------- pythonFiles/tests/test_shell_integration.py | 62 ++++++++-------- 2 files changed, 72 insertions(+), 72 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index 616a59e21203..2b23a5c99f85 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -1,55 +1,55 @@ -import sys +# import sys -original_ps1 = ">>> " +# original_ps1 = ">>> " -class repl_hooks: - def __init__(self): - self.global_exit = None - self.failure_flag = False - self.original_excepthook = sys.excepthook - self.original_displayhook = sys.displayhook - sys.excepthook = self.my_excepthook - sys.displayhook = self.my_displayhook +# class repl_hooks: +# def __init__(self): +# self.global_exit = None +# self.failure_flag = False +# self.original_excepthook = sys.excepthook +# self.original_displayhook = sys.displayhook +# sys.excepthook = self.my_excepthook +# sys.displayhook = self.my_displayhook - def my_displayhook(self, value): - if value is None: - self.failure_flag = False +# def my_displayhook(self, value): +# if value is None: +# self.failure_flag = False - self.original_displayhook(value) +# self.original_displayhook(value) - def my_excepthook(self, type, value, traceback): - self.global_exit = value - self.failure_flag = True +# def my_excepthook(self, type, value, traceback): +# self.global_exit = value +# self.failure_flag = True - self.original_excepthook(type, value, traceback) +# self.original_excepthook(type, value, traceback) -class ps1: - hooks = repl_hooks() - sys.excepthook = hooks.my_excepthook - sys.displayhook = hooks.my_displayhook +# class ps1: +# hooks = repl_hooks() +# sys.excepthook = hooks.my_excepthook +# sys.displayhook = hooks.my_displayhook - # str will get called for every prompt with exit code to show success/failure - def __str__(self): - exit_code = 0 - if self.hooks.failure_flag: - exit_code = 1 - else: - exit_code = 0 +# # str will get called for every prompt with exit code to show success/failure +# def __str__(self): +# exit_code = 0 +# if self.hooks.failure_flag: +# exit_code = 1 +# else: +# exit_code = 0 - # Guide following official VS Code doc for shell integration sequence: - # result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( - # command_finished="\x1b]633;D;" + str(exit_code) + "\x07", - # prompt_started="\x1b]633;A\x07", - # prompt=original_ps1, - # command_start="\x1b]633;B\x07", - # command_executed="\x1b]633;C\x07", - # ) - 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)}" +# # Guide following official VS Code doc for shell integration sequence: +# # result = "{command_finished}{prompt_started}{prompt}{command_start}{command_executed}".format( +# # command_finished="\x1b]633;D;" + str(exit_code) + "\x07", +# # prompt_started="\x1b]633;A\x07", +# # prompt=original_ps1, +# # command_start="\x1b]633;B\x07", +# # command_executed="\x1b]633;C\x07", +# # ) +# 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)}" - return result +# return result -if sys.platform != "win32": - sys.ps1 = ps1() +# if sys.platform != "win32": +# sys.ps1 = ps1() diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index 06bb42499c58..98e2b1f54116 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -1,48 +1,48 @@ -import importlib -from unittest.mock import Mock +# import importlib +# from unittest.mock import Mock -import pythonrc +# import pythonrc -def test_decoration_success(): - importlib.reload(pythonrc) - ps1 = pythonrc.ps1() +# def test_decoration_success(): +# importlib.reload(pythonrc) +# ps1 = pythonrc.ps1() - ps1.hooks.failure_flag = False - result = str(ps1) - assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" +# ps1.hooks.failure_flag = False +# result = str(ps1) +# assert result == "\x1b]633;D;0\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" -def test_decoration_failure(): - importlib.reload(pythonrc) - ps1 = pythonrc.ps1() +# def test_decoration_failure(): +# importlib.reload(pythonrc) +# ps1 = pythonrc.ps1() - ps1.hooks.failure_flag = True - result = str(ps1) +# ps1.hooks.failure_flag = True +# result = str(ps1) - assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" +# assert result == "\x1b]633;D;1\x07\x1b]633;A\x07>>> \x1b]633;B\x07\x1b]633;C\x07" -def test_displayhook_call(): - importlib.reload(pythonrc) - pythonrc.ps1() - mock_displayhook = Mock() +# def test_displayhook_call(): +# importlib.reload(pythonrc) +# pythonrc.ps1() +# mock_displayhook = Mock() - hooks = pythonrc.repl_hooks() - hooks.original_displayhook = mock_displayhook +# hooks = pythonrc.repl_hooks() +# hooks.original_displayhook = mock_displayhook - hooks.my_displayhook("mock_value") +# hooks.my_displayhook("mock_value") - mock_displayhook.assert_called_once_with("mock_value") +# mock_displayhook.assert_called_once_with("mock_value") -def test_excepthook_call(): - importlib.reload(pythonrc) - pythonrc.ps1() - mock_excepthook = Mock() +# def test_excepthook_call(): +# importlib.reload(pythonrc) +# pythonrc.ps1() +# mock_excepthook = Mock() - hooks = pythonrc.repl_hooks() - hooks.original_excepthook = mock_excepthook +# hooks = pythonrc.repl_hooks() +# hooks.original_excepthook = mock_excepthook - hooks.my_excepthook("mock_type", "mock_value", "mock_traceback") - mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback") +# hooks.my_excepthook("mock_type", "mock_value", "mock_traceback") +# mock_excepthook.assert_called_once_with("mock_type", "mock_value", "mock_traceback")