diff --git a/news/2 Fixes/2744.md b/news/2 Fixes/2744.md new file mode 100644 index 000000000000..28c59ff60495 --- /dev/null +++ b/news/2 Fixes/2744.md @@ -0,0 +1 @@ +Ensure relative paths to python interpreters in `python.pythonPath` of `settings.json` are prefixed with `./` or `.\\` (depending on the OS). diff --git a/src/client/interpreter/configuration/services/workspaceFolderUpdaterService.ts b/src/client/interpreter/configuration/services/workspaceFolderUpdaterService.ts index 03c531f8dce9..922c8b0c9f87 100644 --- a/src/client/interpreter/configuration/services/workspaceFolderUpdaterService.ts +++ b/src/client/interpreter/configuration/services/workspaceFolderUpdaterService.ts @@ -14,7 +14,7 @@ export class WorkspaceFolderPythonPathUpdaterService implements IPythonPathUpdat return; } if (pythonPath.startsWith(this.workspaceFolder.fsPath)) { - pythonPath = path.relative(this.workspaceFolder.fsPath, pythonPath); + pythonPath = path.join('.', path.relative(this.workspaceFolder.fsPath, pythonPath)); } await pythonConfig.update('pythonPath', pythonPath, ConfigurationTarget.WorkspaceFolder); } diff --git a/src/client/interpreter/configuration/services/workspaceUpdaterService.ts b/src/client/interpreter/configuration/services/workspaceUpdaterService.ts index 81624581d2f2..b97504a35654 100644 --- a/src/client/interpreter/configuration/services/workspaceUpdaterService.ts +++ b/src/client/interpreter/configuration/services/workspaceUpdaterService.ts @@ -14,7 +14,7 @@ export class WorkspacePythonPathUpdaterService implements IPythonPathUpdaterServ return; } if (pythonPath.startsWith(this.workspace.fsPath)) { - pythonPath = path.relative(this.workspace.fsPath, pythonPath); + pythonPath = path.join('.', path.relative(this.workspace.fsPath, pythonPath)); } await pythonConfig.update('pythonPath', pythonPath, false); } diff --git a/src/test/interpreters/pythonPathUpdater.test.ts b/src/test/interpreters/pythonPathUpdater.test.ts index 35657bf82703..dc2e9bcb78f6 100644 --- a/src/test/interpreters/pythonPathUpdater.test.ts +++ b/src/test/interpreters/pythonPathUpdater.test.ts @@ -80,7 +80,7 @@ suite('Python Path Settings Updater', () => { 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('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); @@ -120,7 +120,7 @@ suite('Python Path Settings Updater', () => { 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('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);