Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Interpreter selection not saved in workspace configuration #7154

Closed
schlamar opened this issue Aug 30, 2019 · 6 comments
Closed

Interpreter selection not saved in workspace configuration #7154

schlamar opened this issue Aug 30, 2019 · 6 comments
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality

Comments

@schlamar
Copy link

Environment data

Expected behaviour

Python interpreter configuration is saved in the *.code-workspace file.

Actual behaviour

Python interpreter configuration is saved in the .vscode/settings.json

Steps to reproduce

  1. Open a workspace
  2. Select a Python interpreter in the status bar
@schlamar schlamar added triage-needed Needs assignment to the proper sub-team bug Issue identified by VS Code Team member as probable bug labels Aug 30, 2019
@schlamar
Copy link
Author

Related to #2125, but not a duplicate.

@karrtikr karrtikr added the triage label Sep 3, 2019
@ghost ghost removed the triage-needed Needs assignment to the proper sub-team label Sep 3, 2019
@kimadeline kimadeline added needs PR and removed triage labels Sep 3, 2019
@kimadeline
Copy link

Cause

In src/client/interpreter/configuration/interpreterSelector.ts we set the configuration target to either be global or the return value of getWorkspaceToSetPythonPath():

if (!setInterpreterGlobally) {
const targetConfig = await this.getWorkspaceToSetPythonPath();
if (!targetConfig) {
return;
}
configTarget = targetConfig.configTarget;
wkspace = targetConfig.folderUri;
}

and getWorkspaceToSetPythonPath only returns workspace folder-level config targets, never workspace:

private async getWorkspaceToSetPythonPath(): Promise<WorkspacePythonPath | undefined> {
if (!Array.isArray(this.workspaceService.workspaceFolders) || this.workspaceService.workspaceFolders.length === 0) {
return undefined;
}
if (this.workspaceService.workspaceFolders.length === 1) {
return { folderUri: this.workspaceService.workspaceFolders[0].uri, configTarget: ConfigurationTarget.WorkspaceFolder };
}
// Ok we have multiple workspaces, get the user to pick a folder.
const workspaceFolder = await this.applicationShell.showWorkspaceFolderPick({ placeHolder: 'Select a workspace' });
return workspaceFolder ? { folderUri: workspaceFolder.uri, configTarget: ConfigurationTarget.WorkspaceFolder } : undefined;
}

So when we call update (VS Code API doc) via updatePythonPath we never update the .code-workspace file:

if (selection !== undefined) {
await this.pythonPathUpdaterService.updatePythonPath(selection.path, configTarget, 'ui', wkspace);
}

@kimadeline kimadeline removed their assignment Sep 3, 2019
@DonJayamanne DonJayamanne added feature-request Request for new features or functionality and removed bug Issue identified by VS Code Team member as probable bug labels Sep 4, 2019
@schlamar
Copy link
Author

schlamar commented Sep 4, 2019

BTW, the API documentation advises, that you should use the WorkspaceConfiguration.update function: https://code.visualstudio.com/api/references/vscode-api#WorkspaceConfiguration.update

Note: it is not advised to use workspace.workspaceFile to write configuration data into the file. You can use workspace.getConfiguration().update() for that purpose which will work both when a single folder is opened as well as an untitled or saved workspace.
(from https://code.visualstudio.com/api/references/vscode-api#workspace.workspaceFile)

@kimadeline
Copy link

Thank you for the heads-up 👍 it's already what we call under the hood in our implementations of IPythonPathUpdaterService.updatePythonPath():

So when we call update (VS Code API doc) via updatePythonPath we never update the .code-workspace file:

@gramster gramster added area-environments Features relating to handling interpreter environments and removed feature-interpreter labels Oct 10, 2019
@kynan
Copy link

kynan commented Jun 28, 2020

This still seems to be an issue with VS Code 1.45.1 and ms-python.python 2020.6.90262

Selecting an interpreter (either via the status bar or the dialog) is not setting python.pythonPath in .vscode/settings.json. This breaks other extensions that rely on that setting, like lextudio.restructuredtext.

@kimadeline
Copy link

Hi @kynan, we deprecated the use of python.pythonPath. Instead, lextudio.restructuredtext should fetch the python interpreter using the API we expose: currently formulahendry/vscode-code-runner#604 (implementation example here), but we will update it to #12596.

Please open a separate issue if you have any further questions.

Closing this issue since we don't save python.PythonPath anymore.

@ghost ghost removed the needs PR label Jun 29, 2020
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 13, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-environments Features relating to handling interpreter environments feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

6 participants