Skip to content

Commit

Permalink
On setups where python.executable property is not available infer jyt…
Browse files Browse the repository at this point in the history
…hon executable path from sys.prefix #2441

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

--HG--
extra : rebase_source : 975f01d2546ae2db43c2c2029dac2741001f0c91
  • Loading branch information
darjus committed Jan 20, 2016
1 parent be7330c commit a20f5f0
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/org/python/core/PySystemState.java
Expand Up @@ -1148,16 +1148,26 @@ private static PyList initArgv(String[] args) {
}

/**
* 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
*/
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);
Expand All @@ -1166,9 +1176,6 @@ private static PyObject initExecutable(Properties props) {
} catch (IOException ioe) {
executableFile = executableFile.getAbsoluteFile();
}
if (!executableFile.isFile()) {
return Py.None;
}
return new PyString(executableFile.getPath());
}

Expand Down

0 comments on commit a20f5f0

Please sign in to comment.