Skip to content

Commit 01d872b

Browse files
authored
Disable PyREPL (#25216)
Resolves: #25164 We can enable shell integration again before python/cpython#126131 Since we are using `PYTHON_BASIC_REPL` there is no need to use bracketed paste mode to avoid indentation error prevalent on the PyREPL from cpython >= 3.13 When there is upstream fix in the future, we should start using bracketed paste mode again, and won't have to inject `PYTHON_BASIC_REPL`
1 parent e5e5241 commit 01d872b

File tree

5 files changed

+19
-14
lines changed

5 files changed

+19
-14
lines changed

src/client/extensionActivation.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ import { DebuggerTypeName } from './debugger/constants';
5353
import { StopWatch } from './common/utils/stopWatch';
5454
import { registerReplCommands, registerReplExecuteOnEnter, registerStartNativeReplCommand } from './repl/replCommands';
5555
import { registerTriggerForTerminalREPL } from './terminals/codeExecution/terminalReplWatcher';
56-
import { registerPythonStartup } from './terminals/pythonStartup';
56+
import { registerBasicRepl, registerPythonStartup } from './terminals/pythonStartup';
5757
import { registerPixiFeatures } from './pythonEnvironments/common/environmentManagers/pixi';
5858
import { registerCustomTerminalLinkProvider } from './terminals/pythonStartupLinkProvider';
5959
import { registerEnvExtFeatures } from './envExt/api.internal';
@@ -184,6 +184,7 @@ async function activateLegacy(ext: ExtensionState, startupStopWatch: StopWatch):
184184
serviceManager.get<ITerminalAutoActivation>(ITerminalAutoActivation).register();
185185

186186
await registerPythonStartup(ext.context);
187+
await registerBasicRepl(ext.context);
187188

188189
serviceManager.get<ICodeExecutionManager>(ICodeExecutionManager).registerCommands();
189190

src/client/terminals/codeExecution/helper.ts

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
5555

5656
public async normalizeLines(
5757
code: string,
58-
replType: ReplType,
58+
_replType: ReplType,
5959
wholeFileContent?: string,
6060
resource?: Uri,
6161
): Promise<string> {
@@ -124,15 +124,6 @@ export class CodeExecutionHelper implements ICodeExecutionHelper {
124124
const lineOffset = object.nextBlockLineno - activeEditor!.selection.start.line - 1;
125125
await this.moveToNextBlock(lineOffset, activeEditor);
126126
}
127-
// For new _pyrepl for Python3.13 and above, we need to send code via bracketed paste mode.
128-
if (object.attach_bracket_paste && replType === ReplType.terminal) {
129-
let trimmedNormalized = object.normalized.replace(/\n$/, '');
130-
if (trimmedNormalized.endsWith(':\n')) {
131-
// In case where statement is unfinished via :, truncate so auto-indentation lands nicely.
132-
trimmedNormalized = trimmedNormalized.replace(/\n$/, '');
133-
}
134-
return `\u001b[200~${trimmedNormalized}\u001b[201~`;
135-
}
136127

137128
return parse(object.normalized);
138129
} catch (ex) {

src/client/terminals/pythonStartup.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,3 +36,8 @@ export async function registerPythonStartup(context: ExtensionContext): Promise<
3636
}),
3737
);
3838
}
39+
40+
export async function registerBasicRepl(context: ExtensionContext): Promise<void> {
41+
// TODO: Configurable by setting
42+
context.environmentVariableCollection.replace('PYTHON_BASIC_REPL', '1');
43+
}

src/test/terminals/codeExecution/helper.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ suite('Terminal - Code Execution Helper', async () => {
137137
editor.setup((e) => e.document).returns(() => document.object);
138138
});
139139

140-
test('normalizeLines should handle attach_bracket_paste correctly', async () => {
140+
test('normalizeLines with BASIC_REPL does not attach bracketed paste mode', async () => {
141141
configurationService
142142
.setup((c) => c.getSettings(TypeMoq.It.isAny()))
143143
.returns({
@@ -163,7 +163,7 @@ suite('Terminal - Code Execution Helper', async () => {
163163

164164
const result = await helper.normalizeLines('print("Looks like you are on 3.13")', ReplType.terminal);
165165

166-
expect(result).to.equal(`\u001b[200~print("Looks like you are on 3.13")\u001b[201~`);
166+
expect(result).to.equal(`print("Looks like you are on 3.13")`);
167167
jsonParseStub.restore();
168168
});
169169

src/test/terminals/shellIntegration/pythonStartup.test.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import {
1616
} from 'vscode';
1717
import { assert } from 'chai';
1818
import * as workspaceApis from '../../../client/common/vscodeApis/workspaceApis';
19-
import { registerPythonStartup } from '../../../client/terminals/pythonStartup';
19+
import { registerBasicRepl, registerPythonStartup } from '../../../client/terminals/pythonStartup';
2020
import { IExtensionContext } from '../../../client/common/types';
2121
import * as pythonStartupLinkProvider from '../../../client/terminals/pythonStartupLinkProvider';
2222
import { CustomTerminalLinkProvider } from '../../../client/terminals/pythonStartupLinkProvider';
@@ -135,6 +135,14 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
135135
globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHONSTARTUP'), TypeMoq.Times.once());
136136
});
137137

138+
test('PYTHON_BASIC_REPL is set when registerBasicRepl is called', async () => {
139+
await registerBasicRepl(context.object);
140+
globalEnvironmentVariableCollection.verify(
141+
(c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()),
142+
TypeMoq.Times.once(),
143+
);
144+
});
145+
138146
test('Ensure registering terminal link calls registerTerminalLinkProvider', async () => {
139147
const registerTerminalLinkProviderStub = sinon.stub(
140148
pythonStartupLinkProvider,

0 commit comments

Comments
 (0)