Auto-detect python 3.5 and above on windows
authorJulien Enselme <jenselme@netbeans.org>
Tue, 11 Oct 2016 18:11:45 +0200
changeset 183867fc277e1cd9d
parent 18385 fabc032831d3
child 18387 a7eceb33fc4f
Auto-detect python 3.5 and above on windows

Starting with Python 3.5, Python is installed in C:\Program Files\Python35. The
current implementation of PythonPlatformManager.findPlatformProperties doesn't
support spaces. I made a patch to correct this. I tested auto-detect on Windows
and on Linux and all seems fine. But if I remember correctly, path in commands
may cause problems on Windows so I'd like input on this. The patch is attached
to this project.
python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java
     1.1 --- a/python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java	Mon Sep 26 18:47:08 2016 +0200
     1.2 +++ b/python.core/src/org/netbeans/modules/python/api/PythonPlatformManager.java	Tue Oct 11 18:11:45 2016 +0200
     1.3 @@ -363,14 +363,29 @@
     1.4          PythonPlatform platform = null;
     1.5          try{
     1.6              PythonExecution pye = new PythonExecution();
     1.7 -            int split = cmd.indexOf(" ");
     1.8 -            pye.setCommand(split > 0 ? cmd.substring(0, split) : cmd);
     1.9 +            String[] cmdParts = cmd.split(" ");
    1.10 +            String cmdWithoutArgs = "";
    1.11 +            String cmdArgs = "";
    1.12 +            boolean isCommandComplete = false;
    1.13 +            for (String cmdPart: cmdParts) {
    1.14 +                if (!isCommandComplete) {
    1.15 +                    cmdWithoutArgs = cmdWithoutArgs + " " + cmdPart;
    1.16 +                } else {
    1.17 +                    cmdArgs = cmdArgs + " " + cmdPart;
    1.18 +                }
    1.19 +
    1.20 +                if (cmdPart.contains("python")) {
    1.21 +                    isCommandComplete = true;
    1.22 +                }
    1.23 +            }
    1.24 +            cmdWithoutArgs = cmdWithoutArgs.trim();
    1.25 +            cmdArgs = cmdArgs.trim();
    1.26 +            pye.setCommand(cmdWithoutArgs);
    1.27              pye.setDisplayName("Python Properties");
    1.28              File info = InstalledFileLocator.getDefault().locate(
    1.29                   "platform_info.py", "org.netbeans.modules.python.core", false);
    1.30              pye.setScript(info.getAbsolutePath());
    1.31 -            if(split > 0) { 
    1.32 -                String cmdArgs = cmd.substring(split).trim();
    1.33 +            if(cmdArgs.length() > 0) {
    1.34                  pye.setCommandArgs(cmdArgs);
    1.35              }
    1.36              pye.setShowControls(false);