Skip to content

Commit

Permalink
Make sure we do not use or execute the default python on PATH if …
Browse files Browse the repository at this point in the history
…there is any other known interpreter (#20457)
  • Loading branch information
Kartik Raj authored Jan 5, 2023
1 parent 4e1f79c commit 2211996
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/client/common/process/pythonExecutionFactory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export class PythonExecutionFactory implements IPythonExecutionFactory {

public async create(options: ExecutionFactoryCreationOptions): Promise<IPythonExecutionService> {
let { pythonPath } = options;
if (!pythonPath) {
if (!pythonPath || pythonPath === 'python') {
// If python path wasn't passed in, we need to auto select it and then read it
// from the configuration.
const interpreterPath = this.interpreterPathExpHelper.get(options.resource);
Expand Down
2 changes: 1 addition & 1 deletion src/client/interpreter/display/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ export class InterpreterDisplay implements IInterpreterDisplay, IExtensionSingle
}
}
private onDidChangeInterpreterInformation(info: PythonEnvironment) {
if (!this.currentlySelectedInterpreterPath || this.currentlySelectedInterpreterPath === info.path) {
if (this.currentlySelectedInterpreterPath === info.path) {
this.updateDisplay(this.currentlySelectedWorkspaceFolder).ignoreErrors();
}
}
Expand Down
17 changes: 16 additions & 1 deletion src/test/common/process/pythonExecutionFactory.unit.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,22 @@ suite('Process - PythonExecutionFactory', () => {
verify(pythonSettings.pythonPath).once();
});

test('If interpreter is explicitly set, ensure we use it', async () => {
test('If interpreter is explicitly set to `python`, ensure we use it', async () => {
const pythonSettings = mock(PythonSettings);
when(processFactory.create(resource)).thenResolve(processService.object);
when(activationHelper.getActivatedEnvironmentVariables(resource)).thenResolve({ x: '1' });
reset(interpreterPathExpHelper);
when(interpreterPathExpHelper.get(anything())).thenReturn('python');
when(autoSelection.autoSelectInterpreter(anything())).thenResolve();
when(configService.getSettings(resource)).thenReturn(instance(pythonSettings));

const service = await factory.create({ resource, pythonPath: 'python' });

expect(service).to.not.equal(undefined);
verify(autoSelection.autoSelectInterpreter(anything())).once();
});

test('Otherwise if interpreter is explicitly set, ensure we use it', async () => {
const pythonSettings = mock(PythonSettings);
when(processFactory.create(resource)).thenResolve(processService.object);
when(activationHelper.getActivatedEnvironmentVariables(resource)).thenResolve({ x: '1' });
Expand Down

0 comments on commit 2211996

Please sign in to comment.