Skip to content

Commit d0e8259

Browse files
Copilotanthonykim1
andcommitted
Apply formatting fixes and finalize PyREPL conditional logic implementation
Co-authored-by: anthonykim1 <[email protected]>
1 parent 4bb50dc commit d0e8259

File tree

2 files changed

+25
-24
lines changed

2 files changed

+25
-24
lines changed

src/client/terminals/pythonStartup.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ export async function registerPythonStartup(context: ExtensionContext): Promise<
4343
async function applyBasicReplSetting(context: ExtensionContext, serviceContainer?: IServiceContainer): Promise<void> {
4444
const config = getConfiguration('python');
4545
const shellIntegrationEnabled = config.get<boolean>('terminal.shellIntegration.enabled');
46-
46+
4747
if (shellIntegrationEnabled && serviceContainer) {
4848
// Only disable PyREPL (set PYTHON_BASIC_REPL=1) when shell integration is enabled
4949
// and Python version is 3.13 or higher
5050
try {
5151
const interpreterService = serviceContainer.get<IInterpreterService>(IInterpreterService);
5252
const pythonMinorVersion = await getPythonMinorVersion(undefined, interpreterService);
53-
53+
5454
if ((pythonMinorVersion ?? 0) >= 13) {
5555
context.environmentVariableCollection.replace('PYTHON_BASIC_REPL', '1');
5656
return;
@@ -59,12 +59,15 @@ async function applyBasicReplSetting(context: ExtensionContext, serviceContainer
5959
// If we can't get the Python version, don't set PYTHON_BASIC_REPL
6060
}
6161
}
62-
62+
6363
// Remove PYTHON_BASIC_REPL if shell integration is disabled or Python < 3.13
6464
context.environmentVariableCollection.delete('PYTHON_BASIC_REPL');
6565
}
6666

67-
export async function registerBasicRepl(context: ExtensionContext, serviceContainer?: IServiceContainer): Promise<void> {
67+
export async function registerBasicRepl(
68+
context: ExtensionContext,
69+
serviceContainer?: IServiceContainer,
70+
): Promise<void> {
6871
await applyBasicReplSetting(context, serviceContainer);
6972
context.subscriptions.push(
7073
onDidChangeConfiguration(async (e) => {

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -137,17 +137,19 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
137137

138138
test('PYTHON_BASIC_REPL is set when shell integration is enabled and Python >= 3.13', async () => {
139139
pythonConfig.setup((p) => p.get('terminal.shellIntegration.enabled')).returns(() => true);
140-
140+
141141
// Mock service container with interpreter service
142142
const serviceContainer = TypeMoq.Mock.ofType<any>();
143143
const interpreterService = TypeMoq.Mock.ofType<any>();
144144
const mockInterpreter = { version: { minor: 13 } };
145-
145+
146146
serviceContainer.setup((sc) => sc.get(TypeMoq.It.isAny())).returns(() => interpreterService.object);
147-
interpreterService.setup((is) => is.getActiveInterpreter(TypeMoq.It.isAny())).returns(() => Promise.resolve(mockInterpreter));
148-
147+
interpreterService
148+
.setup((is) => is.getActiveInterpreter(TypeMoq.It.isAny()))
149+
.returns(() => Promise.resolve(mockInterpreter));
150+
149151
await registerBasicRepl(context.object, serviceContainer.object);
150-
152+
151153
globalEnvironmentVariableCollection.verify(
152154
(c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()),
153155
TypeMoq.Times.once(),
@@ -156,40 +158,36 @@ suite('Terminal - Shell Integration with PYTHONSTARTUP', () => {
156158

157159
test('PYTHON_BASIC_REPL is not set when shell integration is disabled', async () => {
158160
pythonConfig.setup((p) => p.get('terminal.shellIntegration.enabled')).returns(() => false);
159-
161+
160162
await registerBasicRepl(context.object);
161-
163+
162164
globalEnvironmentVariableCollection.verify(
163165
(c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()),
164166
TypeMoq.Times.never(),
165167
);
166-
globalEnvironmentVariableCollection.verify(
167-
(c) => c.delete('PYTHON_BASIC_REPL'),
168-
TypeMoq.Times.once(),
169-
);
168+
globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHON_BASIC_REPL'), TypeMoq.Times.once());
170169
});
171170

172171
test('PYTHON_BASIC_REPL is not set when Python < 3.13 even with shell integration enabled', async () => {
173172
pythonConfig.setup((p) => p.get('terminal.shellIntegration.enabled')).returns(() => true);
174-
173+
175174
// Mock service container with interpreter service for Python 3.12
176175
const serviceContainer = TypeMoq.Mock.ofType<any>();
177176
const interpreterService = TypeMoq.Mock.ofType<any>();
178177
const mockInterpreter = { version: { minor: 12 } };
179-
178+
180179
serviceContainer.setup((sc) => sc.get(TypeMoq.It.isAny())).returns(() => interpreterService.object);
181-
interpreterService.setup((is) => is.getActiveInterpreter(TypeMoq.It.isAny())).returns(() => Promise.resolve(mockInterpreter));
182-
180+
interpreterService
181+
.setup((is) => is.getActiveInterpreter(TypeMoq.It.isAny()))
182+
.returns(() => Promise.resolve(mockInterpreter));
183+
183184
await registerBasicRepl(context.object, serviceContainer.object);
184-
185+
185186
globalEnvironmentVariableCollection.verify(
186187
(c) => c.replace('PYTHON_BASIC_REPL', '1', TypeMoq.It.isAny()),
187188
TypeMoq.Times.never(),
188189
);
189-
globalEnvironmentVariableCollection.verify(
190-
(c) => c.delete('PYTHON_BASIC_REPL'),
191-
TypeMoq.Times.once(),
192-
);
190+
globalEnvironmentVariableCollection.verify((c) => c.delete('PYTHON_BASIC_REPL'), TypeMoq.Times.once());
193191
});
194192

195193
test('Ensure registering terminal link calls registerTerminalLinkProvider', async () => {

0 commit comments

Comments
 (0)