mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
search for Python interpreters in %PATH% (PY-1593)
This commit is contained in:
@@ -18,7 +18,7 @@ public class IronPythonSdkFlavor extends PythonSdkFlavor {
|
||||
public static IronPythonSdkFlavor INSTANCE = new IronPythonSdkFlavor();
|
||||
|
||||
@Override
|
||||
public List<String> suggestHomePaths() {
|
||||
public Collection<String> suggestHomePaths() {
|
||||
List<String> result = new ArrayList<String>();
|
||||
String root = System.getenv("ProgramFiles(x86)");
|
||||
if (root == null) {
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,7 @@ public class MacPythonSdkFlavor extends PythonSdkFlavor {
|
||||
public static MacPythonSdkFlavor INSTANCE = new MacPythonSdkFlavor();
|
||||
|
||||
@Override
|
||||
public List<String> suggestHomePaths() {
|
||||
public Collection<String> suggestHomePaths() {
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
collectPythonInstallations("/Library/Frameworks/Python.framework/Versions", candidates);
|
||||
collectPythonInstallations("/System/Library/Frameworks/Python.framework/Versions", candidates);
|
||||
|
||||
@@ -14,7 +14,7 @@ import java.util.regex.Pattern;
|
||||
* @author yole
|
||||
*/
|
||||
public abstract class PythonSdkFlavor {
|
||||
public List<String> suggestHomePaths() {
|
||||
public Collection<String> suggestHomePaths() {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
@@ -16,7 +17,7 @@ public class UnixPythonSdkFlavor extends PythonSdkFlavor {
|
||||
public static UnixPythonSdkFlavor INSTANCE = new UnixPythonSdkFlavor();
|
||||
|
||||
@Override
|
||||
public List<String> suggestHomePaths() {
|
||||
public Collection<String> suggestHomePaths() {
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
VirtualFile rootDir = LocalFileSystem.getInstance().findFileByPath("/usr/bin");
|
||||
if (rootDir != null) {
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
package com.jetbrains.python.sdk;
|
||||
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.LocalFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.io.File;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* @author yole
|
||||
@@ -22,14 +21,29 @@ public class WinPythonSdkFlavor extends PythonSdkFlavor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> suggestHomePaths() {
|
||||
List<String> candidates = new ArrayList<String>();
|
||||
public Collection<String> suggestHomePaths() {
|
||||
Set<String> candidates = new TreeSet<String>();
|
||||
findSubdirInstallations(candidates, "C:\\", PYTHON_STR, "python.exe");
|
||||
findSubdirInstallations(candidates, "C:\\Program Files\\", PYTHON_STR, "python.exe");
|
||||
findSubdirInstallations(candidates, "C:\\", "jython", "jython.bat");
|
||||
findCandidatesFromPath(candidates, "python.exe");
|
||||
findCandidatesFromPath(candidates, "jython.bat");
|
||||
return candidates;
|
||||
}
|
||||
|
||||
private static void findCandidatesFromPath(Collection<String> candidates, String exeName) {
|
||||
final String path = System.getenv("PATH");
|
||||
for (String pathEntry : StringUtil.split(path, ";")) {
|
||||
if (pathEntry.startsWith("\"") && pathEntry.endsWith("\"")) {
|
||||
pathEntry = pathEntry.substring(1, pathEntry.length()-2);
|
||||
}
|
||||
File f = new File(pathEntry, exeName);
|
||||
if (f.exists()) {
|
||||
candidates.add(f.getPath());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void findSubdirInstallations(Collection<String> candidates, String rootDir, String dir_prefix, String exe_name) {
|
||||
VirtualFile rootVDir = LocalFileSystem.getInstance().findFileByPath(rootDir);
|
||||
if (rootVDir != null) {
|
||||
|
||||
Reference in New Issue
Block a user