From 83242c090d1df4032c0cd1d98fc72c27787a28c8 Mon Sep 17 00:00:00 2001 From: Mikhail Golubev Date: Mon, 26 Feb 2018 17:31:15 +0300 Subject: [PATCH] PY-27954 Don't assume that "lib" dir of venv can contain only pythonX.Y because some packages like mypy can actually install their resources there, and it breaks our detection of built-in and third-party packages. On Windows this check doesn't make sense since there site-packages and copied stdlib modules lie directly inside "Lib", i.e. there is no additional level of nesting. --- .../python/psi/search/PyProjectScopeBuilder.java | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/python/src/com/jetbrains/python/psi/search/PyProjectScopeBuilder.java b/python/src/com/jetbrains/python/psi/search/PyProjectScopeBuilder.java index ab5100b675b7..29f29350f93e 100644 --- a/python/src/com/jetbrains/python/psi/search/PyProjectScopeBuilder.java +++ b/python/src/com/jetbrains/python/psi/search/PyProjectScopeBuilder.java @@ -24,10 +24,12 @@ import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.roots.FileIndexFacade; import com.intellij.openapi.roots.OrderRootType; import com.intellij.openapi.roots.ProjectRootManager; +import com.intellij.openapi.util.SystemInfo; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.search.*; +import com.intellij.util.containers.ContainerUtil; import com.jetbrains.python.codeInsight.typing.PyTypeShed; import com.jetbrains.python.sdk.PythonSdkType; import org.jetbrains.annotations.NotNull; @@ -172,8 +174,11 @@ public class PyProjectScopeBuilder extends ProjectScopeBuilderImpl { if (root != null) { File libRoot = new File(root, "lib"); File[] versionRoots = libRoot.listFiles(); - if (versionRoots != null && versionRoots.length == 1) { - libRoot = versionRoots[0]; + if (versionRoots != null && !SystemInfo.isWindows) { + final File versionRoot = ContainerUtil.find(versionRoots, file -> file.isDirectory() && file.getName().startsWith("python")); + if (versionRoot != null) { + libRoot = versionRoot; + } } for (VirtualFile file : classVFiles) { if (FileUtil.pathsEqual(file.getPath(), libRoot.getPath())) {