diff --git a/python/src/com/jetbrains/python/sdk/PythonSdkType.java b/python/src/com/jetbrains/python/sdk/PythonSdkType.java index 147c9a7c5b6f..b13cb762cae4 100644 --- a/python/src/com/jetbrains/python/sdk/PythonSdkType.java +++ b/python/src/com/jetbrains/python/sdk/PythonSdkType.java @@ -659,9 +659,9 @@ public class PythonSdkType extends SdkType { } public static void addSdkRoot(SdkModificator sdkModificator, String path) { - VirtualFile child = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); - if (child != null) { - addSdkRoot(sdkModificator, child); + final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(path); + if (file != null) { + addSdkRoot(sdkModificator, file); } else { LOG.info("Bogus sys.path entry " + path); @@ -669,19 +669,26 @@ public class PythonSdkType extends SdkType { } private static void addSdkRoot(@NotNull SdkModificator sdkModificator, @NotNull VirtualFile child) { - @NonNls String suffix = child.getExtension(); - if (suffix != null) suffix = suffix.toLowerCase(); // Why on earth empty suffix is null and not ""? - VirtualFile toAdd = child; - if ((!child.isDirectory()) && ("zip".equals(suffix) || "egg".equals(suffix))) { + // NOTE: Files marked as library sources are not considered part of project source. Since the directory of the project the + // user is working on is included in PYTHONPATH with many configurations (e.g. virtualenv), we must not mark SDK paths as + // library sources, only as classes. + sdkModificator.addRoot(getSdkRootVirtualFile(child), OrderRootType.CLASSES); + } + + @NotNull + public static VirtualFile getSdkRootVirtualFile(@NotNull VirtualFile path) { + String suffix = path.getExtension(); + if (suffix != null) { + suffix = suffix.toLowerCase(); // Why on earth empty suffix is null and not ""? + } + if ((!path.isDirectory()) && ("zip".equals(suffix) || "egg".equals(suffix))) { // a .zip / .egg file must have its root extracted first - toAdd = JarFileSystem.getInstance().getJarRootForLocalFile(child); - } - if (toAdd != null) { - // NOTE: Files marked as library sources are not considered part of project source. Since the directory of the project the - // user is working on is included in PYTHONPATH with many configurations (e.g. virtualenv), we must not mark SDK paths as - // library sources, only as classes. - sdkModificator.addRoot(toAdd, OrderRootType.CLASSES); + final VirtualFile jar = JarFileSystem.getInstance().getJarRootForLocalFile(path); + if (jar != null) { + return jar; + } } + return path; } public static String getSkeletonsPath(String basePath, String sdkHome) {