Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
([#16615](https://github.com/Microsoft/vscode-python/issues/16615))
1. Ensure we block on autoselection when no interpreter is explictly set by user.
([#16723](https://github.com/Microsoft/vscode-python/issues/16723))
1. Fix autoselection when opening a python file directly.
([#16733](https://github.com/Microsoft/vscode-python/issues/16733))

### Thanks

Expand Down
11 changes: 3 additions & 8 deletions src/client/common/configSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -679,18 +679,13 @@ export class PythonSettings implements IPythonSettings {
const autoSelectedPythonInterpreter = this.interpreterAutoSelectionService.getAutoSelectedInterpreter(
this.workspaceRoot,
);
if (inExperiment) {
if (autoSelectedPythonInterpreter && this.workspaceRoot) {
this.pythonPath = autoSelectedPythonInterpreter.path;
if (autoSelectedPythonInterpreter) {
this.pythonPath = autoSelectedPythonInterpreter.path;
if (this.workspaceRoot) {
this.interpreterAutoSelectionService
.setWorkspaceInterpreter(this.workspaceRoot, autoSelectedPythonInterpreter)
.ignoreErrors();
}
} else if (autoSelectedPythonInterpreter && this.workspaceRoot) {
this.pythonPath = autoSelectedPythonInterpreter.path;
this.interpreterAutoSelectionService
.setWorkspaceInterpreter(this.workspaceRoot, autoSelectedPythonInterpreter)
.ignoreErrors();
}
}
if (inExperiment && this.pythonPath === DEFAULT_INTERPRETER_SETTING) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import { expect } from 'chai';
import * as path from 'path';
import * as sinon from 'sinon';
import { anything, instance, mock, when } from 'ts-mockito';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import * as typemoq from 'typemoq';
import { Uri, WorkspaceConfiguration } from 'vscode';
import { IWorkspaceService } from '../../../client/common/application/types';
Expand Down Expand Up @@ -118,7 +118,24 @@ suite('Python Settings - pythonPath', () => {

expect(configSettings.pythonPath).to.be.equal('python');
});
test("If we don't have a custom python path and we do have an auto selected interpreter, then use it", () => {
test("If a workspace is opened and if we don't have a custom python path but we do have an auto selected interpreter, then use it", () => {
const pythonPath = path.join(__dirname, 'this is a python path that was auto selected');
const interpreter = { path: pythonPath } as PythonEnvironment;
const workspaceFolderUri = Uri.file(__dirname);
const selectionService = mock(MockAutoSelectionService);
when(selectionService.getAutoSelectedInterpreter(workspaceFolderUri)).thenReturn(interpreter);
when(selectionService.setWorkspaceInterpreter(workspaceFolderUri, anything())).thenResolve();
configSettings = new CustomPythonSettings(workspaceFolderUri, instance(selectionService));
pythonSettings
.setup((p) => p.get(typemoq.It.isValue('pythonPath')))
.returns(() => 'python')
.verifiable(typemoq.Times.atLeast(1));
configSettings.update(pythonSettings.object);

expect(configSettings.pythonPath).to.be.equal(pythonPath);
verify(selectionService.setWorkspaceInterpreter(workspaceFolderUri, interpreter)).once(); // Verify we set the autoselected interpreter
});
test("If no workspace is opened and we don't have a custom python path but we do have an auto selected interpreter, then use it", () => {
const pythonPath = path.join(__dirname, 'this is a python path that was auto selected');
const interpreter = { path: pythonPath } as PythonEnvironment;
const workspaceFolderUri = Uri.file(__dirname);
Expand Down