From 44b183686352a0bd1d302fd0a164d3c31934ca2f Mon Sep 17 00:00:00 2001 From: Don Jayamanne Date: Tue, 7 Nov 2017 11:33:17 -0800 Subject: [PATCH 1/2] Fix detection of virtual envs and auto setting interpreter --- src/client/interpreter/index.ts | 14 ++++++++++---- .../locators/services/virtualEnvService.ts | 11 +++++++++-- 2 files changed, 19 insertions(+), 6 deletions(-) diff --git a/src/client/interpreter/index.ts b/src/client/interpreter/index.ts index c00d6b5973e2..aa1dfa52e821 100644 --- a/src/client/interpreter/index.ts +++ b/src/client/interpreter/index.ts @@ -1,6 +1,6 @@ 'use strict'; import * as path from 'path'; -import { Disposable, StatusBarAlignment, Uri, window, workspace } from 'vscode'; +import { ConfigurationTarget, Disposable, StatusBarAlignment, Uri, window, workspace } from 'vscode'; import { PythonSettings } from '../common/configSettings'; import { PythonPathUpdaterService } from './configuration/pythonPathUpdaterService'; import { PythonPathUpdaterServiceFactory } from './configuration/pythonPathUpdaterServiceFactory'; @@ -71,9 +71,15 @@ export class InterpreterManager implements Disposable { if (!activeWorkspace) { return false; } - const pythonConfig = workspace.getConfiguration('python'); - const pythonPathInConfig = pythonConfig.get('pythonPath', 'python'); - return path.basename(pythonPathInConfig) === pythonPathInConfig; + const pythonConfig = workspace.getConfiguration('python', activeWorkspace.folderUri); + const pythonPathInConfig = pythonConfig.inspect('pythonPath'); + if (activeWorkspace.configTarget === ConfigurationTarget.Workspace){ + return pythonPathInConfig.workspaceValue === undefined || pythonPathInConfig.workspaceValue === 'python'; + } + if (activeWorkspace.configTarget === ConfigurationTarget.WorkspaceFolder){ + return pythonPathInConfig.workspaceFolderValue === undefined || pythonPathInConfig.workspaceFolderValue === 'python'; + } + return false; } private onConfigChanged() { if (this.display) { diff --git a/src/client/interpreter/locators/services/virtualEnvService.ts b/src/client/interpreter/locators/services/virtualEnvService.ts index d7430dad07ad..568936d5f372 100644 --- a/src/client/interpreter/locators/services/virtualEnvService.ts +++ b/src/client/interpreter/locators/services/virtualEnvService.ts @@ -74,8 +74,15 @@ export function getKnownSearchPathsForVirtualEnvs(resource?: Uri): string[] { if (venvPath) { paths.push(untildify(venvPath)); } - if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length === 0) { - paths.push(workspace.workspaceFolders[0].uri.fsPath); + if (Array.isArray(workspace.workspaceFolders) && workspace.workspaceFolders.length > 0) { + if (resource && workspace.workspaceFolders.length > 1) { + const wkspaceFolder = workspace.getWorkspaceFolder(resource); + if (wkspaceFolder) { + paths.push(wkspaceFolder.uri.fsPath); + } + } else { + paths.push(workspace.workspaceFolders[0].uri.fsPath); + } } return paths; } From 79e8d145bd2875a5203b4c8b46e0e4d3aa93ee96 Mon Sep 17 00:00:00 2001 From: Brett Cannon Date: Tue, 7 Nov 2017 13:14:41 -0800 Subject: [PATCH 2/2] Fix formatting --- src/client/interpreter/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/client/interpreter/index.ts b/src/client/interpreter/index.ts index aa1dfa52e821..15f65f1a774e 100644 --- a/src/client/interpreter/index.ts +++ b/src/client/interpreter/index.ts @@ -73,10 +73,10 @@ export class InterpreterManager implements Disposable { } const pythonConfig = workspace.getConfiguration('python', activeWorkspace.folderUri); const pythonPathInConfig = pythonConfig.inspect('pythonPath'); - if (activeWorkspace.configTarget === ConfigurationTarget.Workspace){ + if (activeWorkspace.configTarget === ConfigurationTarget.Workspace) { return pythonPathInConfig.workspaceValue === undefined || pythonPathInConfig.workspaceValue === 'python'; } - if (activeWorkspace.configTarget === ConfigurationTarget.WorkspaceFolder){ + if (activeWorkspace.configTarget === ConfigurationTarget.WorkspaceFolder) { return pythonPathInConfig.workspaceFolderValue === undefined || pythonPathInConfig.workspaceFolderValue === 'python'; } return false;