[Jython-checkins] jython: On setups where python.executable property is not available infer jython

darjus.loktevic jython-checkins at python.org
Wed Jan 20 16:14:09 EST 2016


https://hg.python.org/jython/rev/d9c1b18fcb9b
changeset:   7875:d9c1b18fcb9b
user:        Darjus Loktevic <darjus at gmail.com>
date:        Thu Jan 21 08:08:58 2016 +1100
summary:
  On setups where python.executable property is not available infer jython executable path from sys.prefix #2441

The executable may not exists and it us up to the user to expose a wrapper if needed.

files:
  src/org/python/core/PySystemState.java |  19 +++++++++----
  1 files changed, 13 insertions(+), 6 deletions(-)


diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java
--- a/src/org/python/core/PySystemState.java
+++ b/src/org/python/core/PySystemState.java
@@ -1148,8 +1148,10 @@
     }
 
     /**
-     * Determine the default sys.executable value from the registry. Returns Py.None is no
-     * executable can be found.
+     * Determine the default sys.executable value from the registry.
+     * If registry is not set (as in standalone jython jar), will use sys.prefix + /bin/jython(.exe) and the file may
+     * not exist. Users can create a wrapper in it's place to make it work in embedded environments.
+     * Only if sys.prefix is null, returns Py.None
      *
      * @param props a Properties registry
      * @return a PyObject path string or Py.None
@@ -1157,7 +1159,15 @@
     private static PyObject initExecutable(Properties props) {
         String executable = props.getProperty("python.executable");
         if (executable == null) {
-            return Py.None;
+            if (prefix == null) {
+                return Py.None;
+            } else {
+                if (Platform.IS_WINDOWS) {
+                    executable = prefix.asString() + "/bin/jython.exe";
+                } else {
+                    executable = prefix.asString() + "/bin/jython";
+                }
+            }
         }
 
         File executableFile = new File(executable);
@@ -1166,9 +1176,6 @@
         } catch (IOException ioe) {
             executableFile = executableFile.getAbsoluteFile();
         }
-        if (!executableFile.isFile()) {
-            return Py.None;
-        }
         return new PyString(executableFile.getPath());
     }
 

-- 
Repository URL: https://hg.python.org/jython


More information about the Jython-checkins mailing list