From 65a931cf77b9f7ce7a5b73bef439c211c9bd1e06 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Thu, 16 Nov 2023 16:13:00 -0800 Subject: [PATCH 01/14] inject environment variables --- pythonFiles/.pythonrc | 1 + pythonFiles/normalizeSelection.py | 11 +++++++++++ src/client/common/terminal/service.ts | 6 +++++- .../terminals/codeExecution/terminalCodeExecution.ts | 2 +- 4 files changed, 18 insertions(+), 2 deletions(-) create mode 100644 pythonFiles/.pythonrc diff --git a/pythonFiles/.pythonrc b/pythonFiles/.pythonrc new file mode 100644 index 000000000000..8b137891791f --- /dev/null +++ b/pythonFiles/.pythonrc @@ -0,0 +1 @@ + diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 7ace42daa901..90dc5e225bcf 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -3,11 +3,22 @@ import ast import json +import os +import pathlib import re import sys import textwrap from typing import Iterable +# script_dir = pathlib.Path( +# "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" +# ) +# sys.path.append(os.fspath(script_dir)) +# import debugpy + +# debugpy.connect(5678) +# debugpy.breakpoint() + def split_lines(source): """ diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 7128d27802f8..f6be98fddbc3 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import { inject, injectable } from 'inversify'; +import * as path from 'path'; import { CancellationToken, Disposable, Event, EventEmitter, Terminal } from 'vscode'; import '../../common/extensions'; import { IInterpreterService } from '../../interpreter/contracts'; @@ -10,6 +11,8 @@ import { captureTelemetry } from '../../telemetry'; import { EventName } from '../../telemetry/constants'; import { ITerminalAutoActivation } from '../../terminals/types'; import { ITerminalManager } from '../application/types'; +import { EXTENSION_ROOT_DIR } from '../constants'; +import { _SCRIPTS_DIR } from '../process/internal/scripts/constants'; import { IConfigurationService, IDisposableRegistry } from '../types'; import { ITerminalActivator, @@ -28,6 +31,7 @@ export class TerminalService implements ITerminalService, Disposable { private terminalHelper: ITerminalHelper; private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; + private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', '.pythonrc'); public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); } @@ -76,7 +80,7 @@ export class TerminalService implements ITerminalService, Disposable { this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); this.terminal = this.terminalManager.createTerminal({ name: this.options?.title || 'Python', - env: this.options?.env, + env: { PYTHONSTARTUP: this.envVarScript }, // pass it down to terminalServiceFactory that will eventually pass the env to create terminal hideFromUser: this.options?.hideFromUser, }); this.terminalAutoActivator.disableAutoActivation(this.terminal); diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 50270c3586c4..1a23d94bfee5 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -47,7 +47,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { await this.getTerminalService(resource).sendText(code); } public async initializeRepl(resource: Resource) { - const terminalService = this.getTerminalService(resource); + const terminalService = this.getTerminalService(resource); // pass in env here? if (this.replActive && (await this.replActive)) { await terminalService.show(); return; From b8388ed02367108604ed5e816786496d78a58591 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 16:07:30 -0800 Subject: [PATCH 02/14] pythonrc --- pythonFiles/.pythonrc | 50 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/pythonFiles/.pythonrc b/pythonFiles/.pythonrc index 8b137891791f..083e1480d77e 100644 --- a/pythonFiles/.pythonrc +++ b/pythonFiles/.pythonrc @@ -1 +1,51 @@ +import sys +original_ps1 = ">>>" +global_exit = None +failure_flag = False + +# pytest monkeypatch temp set global variable on a module + + +def my_displayhook(value): + # print(value) + global failure_flag # Tell Python we are using global failure_flag + if value is None: + # did not fail + failure_flag = False + + +def my_excepthook(type, value, traceback): + global global_exit + global_exit = value + global failure_flag + failure_flag = True + + +class PS1: + sys.excepthook = my_excepthook + sys.displayhook = my_displayhook + + def __str__(self): + # This mechanism might fall over on caught errors? + exit_code = 0 + if failure_flag: + exit_code = 1 + else: + exit_code = 0 + + # Pythonic way :) + result = f"{chr(27)}]633;D;{exit_code}0{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) + "0\x07", + # prompt_started="\x1b]633;A\x07", + # prompt=original_ps1, + # command_start="\x1b]633;B\x07", + # # There's no preexec hook? + # command_executed="\x1b]633;C\x07", + # ) + return result + + +sys.ps1 = PS1() From 18ad4d5ee83da1a9c9ace92f6373b08be8911383 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 18:10:28 -0800 Subject: [PATCH 03/14] repl_hook class --- pythonFiles/.pythonrc | 56 ++++++++++++++++++++++++++++++------------- 1 file changed, 40 insertions(+), 16 deletions(-) diff --git a/pythonFiles/.pythonrc b/pythonFiles/.pythonrc index 083e1480d77e..7fabacd28768 100644 --- a/pythonFiles/.pythonrc +++ b/pythonFiles/.pythonrc @@ -1,35 +1,59 @@ import sys original_ps1 = ">>>" -global_exit = None -failure_flag = False +# global_exit = None +# failure_flag = False # pytest monkeypatch temp set global variable on a module -def my_displayhook(value): - # print(value) - global failure_flag # Tell Python we are using global failure_flag - if value is None: - # did not fail - failure_flag = False +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: + # did not fail + self.failure_flag = False -def my_excepthook(type, value, traceback): - global global_exit - global_exit = value - global failure_flag - failure_flag = True + self.original_displayhook(value) + + def my_excepthook(self, type, value, traceback): + self.global_exit = value + self.failure_flag = True + + self.original_excepthook(type, value, traceback) + + +# def my_displayhook(value): +# # print(value) +# global failure_flag # Tell Python we are using global failure_flag +# if value is None: +# # did not fail +# failure_flag = False + + +# def my_excepthook(type, value, traceback): +# global global_exit +# global_exit = value +# global failure_flag +# failure_flag = True class PS1: - sys.excepthook = my_excepthook - sys.displayhook = my_displayhook + hooks = repl_hooks() + sys.excepthook = hooks.my_excepthook + sys.displayhook = hooks.my_displayhook def __str__(self): # This mechanism might fall over on caught errors? exit_code = 0 - if failure_flag: + if self.hooks.failure_flag: exit_code = 1 else: exit_code = 0 From c502e9d9c299fefb46f30c990a89de76dad6122b Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 18:14:32 -0800 Subject: [PATCH 04/14] lint fix --- pythonFiles/.pythonrc | 2 -- pythonFiles/normalizeSelection.py | 5 +++-- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/pythonFiles/.pythonrc b/pythonFiles/.pythonrc index 7fabacd28768..8d738f142f51 100644 --- a/pythonFiles/.pythonrc +++ b/pythonFiles/.pythonrc @@ -4,8 +4,6 @@ original_ps1 = ">>>" # global_exit = None # failure_flag = False -# pytest monkeypatch temp set global variable on a module - class repl_hooks: def __init__(self): diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index 90dc5e225bcf..da2f228ff16a 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -3,8 +3,9 @@ import ast import json -import os -import pathlib + +# import os +# import pathlib import re import sys import textwrap From 1025c98e6a6bacb7f099264b329af230407a9ab3 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 19:56:12 -0800 Subject: [PATCH 05/14] remove comments --- pythonFiles/.pythonrc | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/pythonFiles/.pythonrc b/pythonFiles/.pythonrc index 8d738f142f51..b32ce3795c3f 100644 --- a/pythonFiles/.pythonrc +++ b/pythonFiles/.pythonrc @@ -1,8 +1,6 @@ import sys original_ps1 = ">>>" -# global_exit = None -# failure_flag = False class repl_hooks: @@ -28,28 +26,12 @@ class repl_hooks: self.original_excepthook(type, value, traceback) -# def my_displayhook(value): -# # print(value) -# global failure_flag # Tell Python we are using global failure_flag -# if value is None: -# # did not fail -# failure_flag = False - - -# def my_excepthook(type, value, traceback): -# global global_exit -# global_exit = value -# global failure_flag -# failure_flag = True - - class PS1: hooks = repl_hooks() sys.excepthook = hooks.my_excepthook sys.displayhook = hooks.my_displayhook def __str__(self): - # This mechanism might fall over on caught errors? exit_code = 0 if self.hooks.failure_flag: exit_code = 1 From dd6b847f886f35e0ea56110118cd409928b919c7 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 21:01:36 -0800 Subject: [PATCH 06/14] add success and failure test decoration --- pythonFiles/{.pythonrc => pythonrc.py} | 0 pythonFiles/tests/test_shell_integration.py | 22 +++++++++++++++++++++ src/client/common/terminal/service.ts | 2 +- 3 files changed, 23 insertions(+), 1 deletion(-) rename pythonFiles/{.pythonrc => pythonrc.py} (100%) create mode 100644 pythonFiles/tests/test_shell_integration.py diff --git a/pythonFiles/.pythonrc b/pythonFiles/pythonrc.py similarity index 100% rename from pythonFiles/.pythonrc rename to pythonFiles/pythonrc.py diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py new file mode 100644 index 000000000000..99410f480741 --- /dev/null +++ b/pythonFiles/tests/test_shell_integration.py @@ -0,0 +1,22 @@ +import importlib + +import pythonrc + + +def test_decoration_success(): + importlib.reload(pythonrc) + ps1 = pythonrc.PS1() + + ps1.hooks.failure_flag = False + result = str(ps1) + assert result == "\x1b]633;D;00\x07\x1b]633;A\x07>>>\x1b]633;B\x07\x1b]633;C\x07" + + +def test_decoration_failure(): + importlib.reload(pythonrc) + ps1 = pythonrc.PS1() + + ps1.hooks.failure_flag = True + result = str(ps1) + + assert result == "\x1b]633;D;10\x07\x1b]633;A\x07>>>\x1b]633;B\x07\x1b]633;C\x07" diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index f6be98fddbc3..e2a99911edd1 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -31,7 +31,7 @@ export class TerminalService implements ITerminalService, Disposable { private terminalHelper: ITerminalHelper; private terminalActivator: ITerminalActivator; private terminalAutoActivator: ITerminalAutoActivation; - private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', '.pythonrc'); + private readonly envVarScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'pythonrc.py'); public get onDidCloseTerminal(): Event { return this.terminalClosed.event.bind(this.terminalClosed); } From 11a95d34e7e97b36b1fe8b764e2782dd2365351e Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 21:17:25 -0800 Subject: [PATCH 07/14] add displayhook and excepthook test --- pythonFiles/tests/test_shell_integration.py | 26 +++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index 99410f480741..7d600acaff3d 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -1,4 +1,5 @@ import importlib +from unittest.mock import Mock import pythonrc @@ -20,3 +21,28 @@ def test_decoration_failure(): result = str(ps1) assert result == "\x1b]633;D;10\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() + + hooks = pythonrc.repl_hooks() + hooks.original_displayhook = mock_displayhook + + hooks.my_displayhook("mock_value") + + mock_displayhook.assert_called_once_with("mock_value") + + +def test_excepthook_call(): + importlib.reload(pythonrc) + pythonrc.PS1() + mock_excepthook = Mock() + + 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") From 3b6f4a34b5fae0a440812effc3493bd8b139ef8c Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 23:00:16 -0800 Subject: [PATCH 08/14] PYTHONSTARTUP test --- src/client/common/terminal/service.ts | 2 +- .../common/terminals/service.unit.test.ts | 33 +++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index e2a99911edd1..8bd224808657 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -73,7 +73,7 @@ export class TerminalService implements ITerminalService, Disposable { this.terminal!.show(preserveFocus); } } - private async ensureTerminal(preserveFocus: boolean = true): Promise { + public async ensureTerminal(preserveFocus: boolean = true): Promise { if (this.terminal) { return; } diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index 2f0d86f4000f..770884505c47 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -2,6 +2,7 @@ // Licensed under the MIT License. import { expect } from 'chai'; +import path from 'path'; import * as TypeMoq from 'typemoq'; import { Disposable, Terminal as VSCodeTerminal, WorkspaceConfiguration } from 'vscode'; import { ITerminalManager, IWorkspaceService } from '../../../client/common/application/types'; @@ -9,6 +10,7 @@ import { IPlatformService } from '../../../client/common/platform/types'; import { TerminalService } from '../../../client/common/terminal/service'; import { ITerminalActivator, ITerminalHelper, TerminalShellType } from '../../../client/common/terminal/types'; import { IDisposableRegistry } from '../../../client/common/types'; +import { EXTENSION_ROOT_DIR } from '../../../client/constants'; import { IServiceContainer } from '../../../client/ioc/types'; import { ITerminalAutoActivation } from '../../../client/terminals/types'; import { createPythonInterpreter } from '../../utils/interpreters'; @@ -158,6 +160,37 @@ suite('Terminal Service', () => { terminal.verify((t) => t.show(TypeMoq.It.isValue(false)), TypeMoq.Times.exactly(2)); }); + test('Ensure PYTHONSTARTUP is injected', async () => { + service = new TerminalService(mockServiceContainer.object); + terminalActivator + .setup((h) => h.activateEnvironmentInTerminal(TypeMoq.It.isAny(), TypeMoq.It.isAny())) + .returns(() => Promise.resolve(true)) + .verifiable(TypeMoq.Times.once()); + terminalManager + .setup((t) => t.createTerminal(TypeMoq.It.isAny())) + .returns(() => terminal.object) + .verifiable(TypeMoq.Times.atLeastOnce()); + const envVarScript = path.join(EXTENSION_ROOT_DIR, 'pythonFiles', 'pythonrc.py'); + terminalManager + .setup((t) => + t.createTerminal({ + name: TypeMoq.It.isAny(), + env: TypeMoq.It.isObjectWith({ PYTHONSTARTUP: envVarScript }), + hideFromUser: TypeMoq.It.isAny(), + }), + ) + .returns(() => terminal.object) + .verifiable(TypeMoq.Times.atLeastOnce()); + await service.show(); + await service.show(); + await service.show(); + await service.show(); + + terminalHelper.verifyAll(); + terminalActivator.verifyAll(); + terminal.verify((t) => t.show(TypeMoq.It.isValue(true)), TypeMoq.Times.atLeastOnce()); + }); + test('Ensure terminal is activated once after creation', async () => { service = new TerminalService(mockServiceContainer.object); terminalActivator From 47ccde5af6651df45f85d32aad417e83cc141dc6 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 23:06:22 -0800 Subject: [PATCH 09/14] different extension root dir --- src/test/common/terminals/service.unit.test.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index 770884505c47..faddfa60b34a 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -6,11 +6,12 @@ import path from 'path'; import * as TypeMoq from 'typemoq'; import { Disposable, Terminal as VSCodeTerminal, WorkspaceConfiguration } from 'vscode'; import { ITerminalManager, IWorkspaceService } from '../../../client/common/application/types'; +import { EXTENSION_ROOT_DIR } from '../../../client/common/constants'; import { IPlatformService } from '../../../client/common/platform/types'; import { TerminalService } from '../../../client/common/terminal/service'; import { ITerminalActivator, ITerminalHelper, TerminalShellType } from '../../../client/common/terminal/types'; import { IDisposableRegistry } from '../../../client/common/types'; -import { EXTENSION_ROOT_DIR } from '../../../client/constants'; + import { IServiceContainer } from '../../../client/ioc/types'; import { ITerminalAutoActivation } from '../../../client/terminals/types'; import { createPythonInterpreter } from '../../utils/interpreters'; From 158919fce9413a501eac70a24e037d9bea543371 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Mon, 20 Nov 2023 23:12:41 -0800 Subject: [PATCH 10/14] import path --- src/test/common/terminals/service.unit.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index faddfa60b34a..45c8c3482bc1 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -2,7 +2,7 @@ // Licensed under the MIT License. import { expect } from 'chai'; -import path from 'path'; +import * as path from 'path'; import * as TypeMoq from 'typemoq'; import { Disposable, Terminal as VSCodeTerminal, WorkspaceConfiguration } from 'vscode'; import { ITerminalManager, IWorkspaceService } from '../../../client/common/application/types'; From a0098282ff1e1705dd3a7f41d65ea4843eb5b0b5 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 21 Nov 2023 00:12:28 -0800 Subject: [PATCH 11/14] clean up --- pythonFiles/normalizeSelection.py | 12 ------------ pythonFiles/pythonrc.py | 6 ++---- src/client/common/terminal/service.ts | 2 +- .../terminals/codeExecution/terminalCodeExecution.ts | 2 +- 4 files changed, 4 insertions(+), 18 deletions(-) diff --git a/pythonFiles/normalizeSelection.py b/pythonFiles/normalizeSelection.py index da2f228ff16a..7ace42daa901 100644 --- a/pythonFiles/normalizeSelection.py +++ b/pythonFiles/normalizeSelection.py @@ -3,23 +3,11 @@ import ast import json - -# import os -# import pathlib import re import sys import textwrap from typing import Iterable -# script_dir = pathlib.Path( -# "User/anthonykim/Desktop/vscode-python/pythonFiles/lib/python" -# ) -# sys.path.append(os.fspath(script_dir)) -# import debugpy - -# debugpy.connect(5678) -# debugpy.breakpoint() - def split_lines(source): """ diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index b32ce3795c3f..c066c1f536aa 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -26,7 +26,7 @@ def my_excepthook(self, type, value, traceback): self.original_excepthook(type, value, traceback) -class PS1: +class ps1: hooks = repl_hooks() sys.excepthook = hooks.my_excepthook sys.displayhook = hooks.my_displayhook @@ -38,7 +38,6 @@ def __str__(self): else: exit_code = 0 - # Pythonic way :) result = f"{chr(27)}]633;D;{exit_code}0{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( @@ -46,10 +45,9 @@ def __str__(self): # prompt_started="\x1b]633;A\x07", # prompt=original_ps1, # command_start="\x1b]633;B\x07", - # # There's no preexec hook? # command_executed="\x1b]633;C\x07", # ) return result -sys.ps1 = PS1() +sys.ps1 = ps1() diff --git a/src/client/common/terminal/service.ts b/src/client/common/terminal/service.ts index 8bd224808657..cf63603a2e9b 100644 --- a/src/client/common/terminal/service.ts +++ b/src/client/common/terminal/service.ts @@ -80,7 +80,7 @@ export class TerminalService implements ITerminalService, Disposable { this.terminalShellType = this.terminalHelper.identifyTerminalShell(this.terminal); this.terminal = this.terminalManager.createTerminal({ name: this.options?.title || 'Python', - env: { PYTHONSTARTUP: this.envVarScript }, // pass it down to terminalServiceFactory that will eventually pass the env to create terminal + env: { PYTHONSTARTUP: this.envVarScript }, hideFromUser: this.options?.hideFromUser, }); this.terminalAutoActivator.disableAutoActivation(this.terminal); diff --git a/src/client/terminals/codeExecution/terminalCodeExecution.ts b/src/client/terminals/codeExecution/terminalCodeExecution.ts index 1a23d94bfee5..50270c3586c4 100644 --- a/src/client/terminals/codeExecution/terminalCodeExecution.ts +++ b/src/client/terminals/codeExecution/terminalCodeExecution.ts @@ -47,7 +47,7 @@ export class TerminalCodeExecutionProvider implements ICodeExecutionService { await this.getTerminalService(resource).sendText(code); } public async initializeRepl(resource: Resource) { - const terminalService = this.getTerminalService(resource); // pass in env here? + const terminalService = this.getTerminalService(resource); if (this.replActive && (await this.replActive)) { await terminalService.show(); return; From 8477b172f7c6a82e422850c094dcf47a2d40afbc Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 21 Nov 2023 00:16:35 -0800 Subject: [PATCH 12/14] clean up --- pythonFiles/pythonrc.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/pythonFiles/pythonrc.py b/pythonFiles/pythonrc.py index c066c1f536aa..a3d09ce9c11c 100644 --- a/pythonFiles/pythonrc.py +++ b/pythonFiles/pythonrc.py @@ -14,7 +14,6 @@ def __init__(self): def my_displayhook(self, value): if value is None: - # did not fail self.failure_flag = False self.original_displayhook(value) @@ -31,6 +30,7 @@ class ps1: 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: @@ -38,8 +38,7 @@ def __str__(self): else: exit_code = 0 - result = f"{chr(27)}]633;D;{exit_code}0{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) + "0\x07", # prompt_started="\x1b]633;A\x07", @@ -47,6 +46,8 @@ def __str__(self): # command_start="\x1b]633;B\x07", # command_executed="\x1b]633;C\x07", # ) + result = f"{chr(27)}]633;D;{exit_code}0{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 f7d8617fdc15989b7dcc01e3e1b97333e7997ad1 Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 21 Nov 2023 00:17:59 -0800 Subject: [PATCH 13/14] delete white space --- src/test/common/terminals/service.unit.test.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/test/common/terminals/service.unit.test.ts b/src/test/common/terminals/service.unit.test.ts index 45c8c3482bc1..7336f7094e6e 100644 --- a/src/test/common/terminals/service.unit.test.ts +++ b/src/test/common/terminals/service.unit.test.ts @@ -11,7 +11,6 @@ import { IPlatformService } from '../../../client/common/platform/types'; import { TerminalService } from '../../../client/common/terminal/service'; import { ITerminalActivator, ITerminalHelper, TerminalShellType } from '../../../client/common/terminal/types'; import { IDisposableRegistry } from '../../../client/common/types'; - import { IServiceContainer } from '../../../client/ioc/types'; import { ITerminalAutoActivation } from '../../../client/terminals/types'; import { createPythonInterpreter } from '../../utils/interpreters'; From 3d9860e5a29ee4fbafde7031300aa556377bd01a Mon Sep 17 00:00:00 2001 From: Anthony Kim Date: Tue, 21 Nov 2023 00:23:25 -0800 Subject: [PATCH 14/14] lowercase cleanup --- pythonFiles/tests/test_shell_integration.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pythonFiles/tests/test_shell_integration.py b/pythonFiles/tests/test_shell_integration.py index 7d600acaff3d..e45aeb60470e 100644 --- a/pythonFiles/tests/test_shell_integration.py +++ b/pythonFiles/tests/test_shell_integration.py @@ -6,7 +6,7 @@ def test_decoration_success(): importlib.reload(pythonrc) - ps1 = pythonrc.PS1() + ps1 = pythonrc.ps1() ps1.hooks.failure_flag = False result = str(ps1) @@ -15,7 +15,7 @@ def test_decoration_success(): def test_decoration_failure(): importlib.reload(pythonrc) - ps1 = pythonrc.PS1() + ps1 = pythonrc.ps1() ps1.hooks.failure_flag = True result = str(ps1) @@ -25,7 +25,7 @@ def test_decoration_failure(): def test_displayhook_call(): importlib.reload(pythonrc) - pythonrc.PS1() + pythonrc.ps1() mock_displayhook = Mock() hooks = pythonrc.repl_hooks() @@ -38,7 +38,7 @@ def test_displayhook_call(): def test_excepthook_call(): importlib.reload(pythonrc) - pythonrc.PS1() + pythonrc.ps1() mock_excepthook = Mock() hooks = pythonrc.repl_hooks()