Improve auto detection of Python on linux
authorJulien Enselme <jenselme@netbeans.org>
Mon, 19 Sep 2016 16:24:45 +0200
changeset 18378e9f2e11b9638
parent 18377 4c0a7a6488cf
child 18379 91dd6de4e7c9
Improve auto detection of Python on linux

- Correctly detects all Python executable in /usr/bin (including Python 3 and
Python 2)
- Detects Pypy
python.core/src/org/netbeans/modules/python/api/PythonAutoDetector.java
python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java
     1.1 --- a/python.core/src/org/netbeans/modules/python/api/PythonAutoDetector.java	Mon Sep 19 14:59:43 2016 +0200
     1.2 +++ b/python.core/src/org/netbeans/modules/python/api/PythonAutoDetector.java	Mon Sep 19 16:24:45 2016 +0200
     1.3 @@ -78,8 +78,13 @@
     1.4                  name = dir.getName();
     1.5                  ext = "";
     1.6              }
     1.7 -            if( name.equalsIgnoreCase("jython") || name.equalsIgnoreCase("python")) {
     1.8 -                if (Utilities.isWindows()){
     1.9 +            if (name.equalsIgnoreCase("jython")
    1.10 +                    || name.equalsIgnoreCase("python")
    1.11 +                    || name.equalsIgnoreCase("python2")
    1.12 +                    || name.equalsIgnoreCase("python3")
    1.13 +                    || name.equalsIgnoreCase("pypy")
    1.14 +                    || name.equalsIgnoreCase("pypy3")) {
    1.15 +                if (Utilities.isWindows()) {
    1.16                      if (ext.equalsIgnoreCase("exe") || ext.equalsIgnoreCase("bat")) {
    1.17                          if( addMatch(dir.getAbsolutePath())) { //don't report duplicates
    1.18                              if (LOGGER.isLoggable(Level.CONFIG)) {
    1.19 @@ -236,7 +241,8 @@
    1.20          if (dir.isDirectory()) { //are we already IN the ?ython dir?
    1.21              String spath = dir.getName();
    1.22              if( spath.toLowerCase().contains("jython") ||
    1.23 -                spath.toLowerCase().contains("python") ){
    1.24 +                spath.toLowerCase().contains("python") ||
    1.25 +                spath.toLowerCase().contains("pypy") ){
    1.26                  searchNestedDirectoies = true; // must set each time
    1.27                  processAction(dir);
    1.28                  return;
    1.29 @@ -246,12 +252,13 @@
    1.30              if(children != null){
    1.31                  for (int i=0; i<children.length; i++) {
    1.32                      File fDirectory = new File(dir, children[i]);
    1.33 -                    if (fDirectory.isDirectory()){
    1.34 +                    if (fDirectory.isDirectory() || fDirectory.isFile()) {
    1.35                          spath = fDirectory.getName();
    1.36 -                        if( spath.toLowerCase().contains("jython") ||
    1.37 -                            spath.toLowerCase().contains("python") ){
    1.38 -                        searchNestedDirectoies = true; // must set each time
    1.39 -                        processAction(fDirectory);
    1.40 +                        if (spath.toLowerCase().contains("jython")
    1.41 +                                || spath.toLowerCase().contains("python")
    1.42 +                                || spath.toLowerCase().contains("pypy")) {
    1.43 +                            searchNestedDirectoies = true; // must set each time
    1.44 +                            processAction(fDirectory);
    1.45                          }
    1.46                      }
    1.47                  }
     2.1 --- a/python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java	Mon Sep 19 14:59:43 2016 +0200
     2.2 +++ b/python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java	Mon Sep 19 16:24:45 2016 +0200
     2.3 @@ -476,17 +476,6 @@
     2.4                      ad.traverseEnvPaths();
     2.5                      ad.searchNestedDirectoies = true;
     2.6                      ad.traverseDirectory(new File("/usr/bin")); // NOI18N // for all other (probably Unix-like) systems
     2.7 -                    
     2.8 -                    File fDefault = new File("/usr/bin/python"); // NOI18N  Default Python
     2.9 -                    String path = fDefault.getAbsolutePath();
    2.10 -                    PythonPlatform platform = findPlatformProperties(path, null);
    2.11 -                    if (platform != null) {
    2.12 -                        try {
    2.13 -                            storePlatform(platform);
    2.14 -                        } catch (IOException ioe) {
    2.15 -                            Exceptions.printStackTrace(ioe);
    2.16 -                        }
    2.17 -                    }
    2.18                  }
    2.19              }
    2.20