From 7a2e2cdbe871a3a12f0017385bb58fd69b3f0ff0 Mon Sep 17 00:00:00 2001 From: Ekaterina Tuzova Date: Mon, 17 Nov 2014 14:50:05 +0300 Subject: [PATCH] fixed PY-13531 Stop executing $world when it looks like a python binary. --- .../com/jetbrains/python/sdk/flavors/CPythonSdkFlavor.java | 3 +++ .../jetbrains/python/sdk/flavors/UnixPythonSdkFlavor.java | 6 +++--- .../jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java | 7 +++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/python/src/com/jetbrains/python/sdk/flavors/CPythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/CPythonSdkFlavor.java index 62448004d574..da0f236205d0 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/CPythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/CPythonSdkFlavor.java @@ -17,10 +17,13 @@ package com.jetbrains.python.sdk.flavors; import org.jetbrains.annotations.NotNull; +import java.util.regex.Pattern; + /** * @author yole */ public abstract class CPythonSdkFlavor extends PythonSdkFlavor { + public final static Pattern PYTHON_RE = Pattern.compile("python-?(\\d\\.\\d)?|python-?(\\d)?"); @NotNull @Override public String getName() { diff --git a/python/src/com/jetbrains/python/sdk/flavors/UnixPythonSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/UnixPythonSdkFlavor.java index cf18921e017c..a424614d1338 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/UnixPythonSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/UnixPythonSdkFlavor.java @@ -31,7 +31,7 @@ public class UnixPythonSdkFlavor extends CPythonSdkFlavor { private UnixPythonSdkFlavor() { } - private final static String[] NAMES = new String[]{"python", "jython", "pypy"}; + private final static String[] NAMES = new String[]{"jython", "pypy"}; public static UnixPythonSdkFlavor INSTANCE = new UnixPythonSdkFlavor(); @@ -52,9 +52,9 @@ public class UnixPythonSdkFlavor extends CPythonSdkFlavor { VirtualFile[] suspects = rootDir.getChildren(); for (VirtualFile child : suspects) { if (!child.isDirectory()) { - final String childName = child.getName(); + final String childName = child.getName().toLowerCase(); for (String name : NAMES) { - if (childName.startsWith(name)) { + if (childName.startsWith(name) || PYTHON_RE.matcher(childName).matches()) { String childPath = child.getPath(); if (FileSystemUtil.isSymLink(childPath)) { childPath = FileSystemUtil.resolveSymLink(childPath); diff --git a/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java b/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java index 576a66279900..7918f63ff77d 100644 --- a/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java +++ b/python/src/com/jetbrains/python/sdk/flavors/VirtualEnvSdkFlavor.java @@ -41,8 +41,7 @@ import java.util.List; public class VirtualEnvSdkFlavor extends CPythonSdkFlavor { private VirtualEnvSdkFlavor() { } - - private final static String[] NAMES = new String[]{"python", "jython", "pypy", "python.exe", "jython.bat", "pypy.exe"}; + private final static String[] NAMES = new String[]{"jython", "pypy", "python.exe", "jython.bat", "pypy.exe"}; public static VirtualEnvSdkFlavor INSTANCE = new VirtualEnvSdkFlavor(); @@ -107,7 +106,7 @@ public class VirtualEnvSdkFlavor extends CPythonSdkFlavor { private static String findInterpreter(VirtualFile dir) { for (VirtualFile child : dir.getChildren()) { if (!child.isDirectory()) { - final String childName = child.getName(); + final String childName = child.getName().toLowerCase(); for (String name : NAMES) { if (SystemInfo.isWindows) { if (childName.equals(name)) { @@ -115,7 +114,7 @@ public class VirtualEnvSdkFlavor extends CPythonSdkFlavor { } } else { - if (childName.startsWith(name)) { + if (childName.startsWith(name) || PYTHON_RE.matcher(childName).matches()) { if (!childName.endsWith("-config")) { return child.getPath(); }