Skip to content

Commit 2211996

Browse files
author
Kartik Raj
authored
Make sure we do not use or execute the default python on PATH if there is any other known interpreter (#20457)
1 parent 4e1f79c commit 2211996

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

src/client/common/process/pythonExecutionFactory.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {
5151

5252
public async create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService> {
5353
let { pythonPath } = options;
54-
if (!pythonPath) {
54+
if (!pythonPath || pythonPath === 'python') {
5555
// If python path wasn't passed in, we need to auto select it and then read it
5656
// from the configuration.
5757
const interpreterPath = this.interpreterPathExpHelper.get(options.resource);

src/client/interpreter/display/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
108108
}
109109
}
110110
private onDidChangeInterpreterInformation(info: PythonEnvironment) {
111-
if (!this.currentlySelectedInterpreterPath || this.currentlySelectedInterpreterPath === info.path) {
111+
if (this.currentlySelectedInterpreterPath === info.path) {
112112
this.updateDisplay(this.currentlySelectedWorkspaceFolder).ignoreErrors();
113113
}
114114
}

src/test/common/process/pythonExecutionFactory.unit.test.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,22 @@ suite('Process - PythonExecutionFactory', () => {
153153
verify(pythonSettings.pythonPath).once();
154154
});
155155

156-
test('If interpreter is explicitly set, ensure we use it', async () => {
156+
test('If interpreter is explicitly set to `python`, ensure we use it', async () => {
157+
const pythonSettings = mock(PythonSettings);
158+
when(processFactory.create(resource)).thenResolve(processService.object);
159+
when(activationHelper.getActivatedEnvironmentVariables(resource)).thenResolve({ x: '1' });
160+
reset(interpreterPathExpHelper);
161+
when(interpreterPathExpHelper.get(anything())).thenReturn('python');
162+
when(autoSelection.autoSelectInterpreter(anything())).thenResolve();
163+
when(configService.getSettings(resource)).thenReturn(instance(pythonSettings));
164+
165+
const service = await factory.create({ resource, pythonPath: 'python' });
166+
167+
expect(service).to.not.equal(undefined);
168+
verify(autoSelection.autoSelectInterpreter(anything())).once();
169+
});
170+
171+
test('Otherwise if interpreter is explicitly set, ensure we use it', async () => {
157172
const pythonSettings = mock(PythonSettings);
158173
when(processFactory.create(resource)).thenResolve(processService.object);
159174
when(activationHelper.getActivatedEnvironmentVariables(resource)).thenResolve({ x: '1' });

0 commit comments

Comments
 (0)