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

[Fixes #2459] Do not use a variable substitution when updating python.pythonPath. #2685

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 news/2 Fixes/2459.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Do not use variable substitution when updating python.pythonPath. This matters
because VS Code does not do variable substitution in settings values.
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export class WorkspaceFolderPythonPathUpdaterService implements IPythonPathUpdat
return;
}
if (pythonPath.startsWith(this.workspaceFolder.fsPath)) {
// tslint:disable-next-line:no-invalid-template-strings
pythonPath = path.join('${workspaceFolder}', path.relative(this.workspaceFolder.fsPath, pythonPath));
pythonPath = path.relative(this.workspaceFolder.fsPath, pythonPath);
}
await pythonConfig.update('pythonPath', pythonPath, ConfigurationTarget.WorkspaceFolder);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ export class WorkspacePythonPathUpdaterService implements IPythonPathUpdaterServ
return;
}
if (pythonPath.startsWith(this.workspace.fsPath)) {
// tslint:disable-next-line:no-invalid-template-strings
pythonPath = path.join('${workspaceFolder}', path.relative(this.workspace.fsPath, pythonPath));
pythonPath = path.relative(this.workspace.fsPath, pythonPath);
}
await pythonConfig.update('pythonPath', pythonPath, false);
}
Expand Down
8 changes: 4 additions & 4 deletions src/test/interpreters/pythonPathUpdater.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,12 @@ suite('Python Path Settings Updater', () => {
await updater.updatePythonPath(pythonPath);
workspaceConfig.verify(w => w.update(TypeMoq.It.isValue('pythonPath'), TypeMoq.It.isValue(pythonPath), TypeMoq.It.isValue(ConfigurationTarget.WorkspaceFolder)), TypeMoq.Times.once());
});
test('Python Path should be updated with ${workspaceFolder} for relative paths', async () => {
test('Python Path should be truncated for worspace-relative paths', async () => {
const workspaceFolderPath = path.join('user', 'desktop', 'development');
const workspaceFolder = Uri.file(workspaceFolderPath);
const updater = updaterServiceFactory.getWorkspaceFolderPythonPathConfigurationService(workspaceFolder);
const pythonPath = Uri.file(path.join(workspaceFolderPath, 'env', 'bin', 'python')).fsPath;
const expectedPythonPath = path.join('${workspaceFolder}', 'env', 'bin', 'python');
const expectedPythonPath = path.join('env', 'bin', 'python');
const workspaceConfig = setupConfigProvider(workspaceFolder);
workspaceConfig.setup(w => w.inspect(TypeMoq.It.isValue('pythonPath'))).returns(() => undefined);

Expand Down Expand Up @@ -115,12 +115,12 @@ suite('Python Path Settings Updater', () => {
await updater.updatePythonPath(pythonPath);
workspaceConfig.verify(w => w.update(TypeMoq.It.isValue('pythonPath'), TypeMoq.It.isValue(pythonPath), TypeMoq.It.isValue(false)), TypeMoq.Times.once());
});
test('Python Path should be updated with ${workspaceFolder} for relative paths', async () => {
test('Python Path should be truncated for workspace-relative paths', async () => {
const workspaceFolderPath = path.join('user', 'desktop', 'development');
const workspaceFolder = Uri.file(workspaceFolderPath);
const updater = updaterServiceFactory.getWorkspacePythonPathConfigurationService(workspaceFolder);
const pythonPath = Uri.file(path.join(workspaceFolderPath, 'env', 'bin', 'python')).fsPath;
const expectedPythonPath = path.join('${workspaceFolder}', 'env', 'bin', 'python');
const expectedPythonPath = path.join('env', 'bin', 'python');
const workspaceConfig = setupConfigProvider(workspaceFolder);
workspaceConfig.setup(w => w.inspect(TypeMoq.It.isValue('pythonPath'))).returns(() => undefined);

Expand Down