-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathPythonUtils.java
More file actions
37 lines (28 loc) · 1.53 KB
/
PythonUtils.java
File metadata and controls
37 lines (28 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package nodebox.client;
import org.python.core.Py;
import org.python.core.PyString;
import org.python.core.PySystemState;
import java.io.File;
import java.util.Properties;
public class PythonUtils {
public static void initializePython() {
// Set the Jython package cache directory.
Properties jythonProperties = new Properties();
String jythonCacheDir = PlatformUtils.getUserDataDirectory() + PlatformUtils.SEP + "_jythoncache";
jythonProperties.put("python.cachedir", jythonCacheDir);
// Initialize Python.
PySystemState.initialize(System.getProperties(), jythonProperties, new String[]{""});
// Add the built-in Python libraries.
String workingDirectory = System.getProperty("user.dir");
File pythonLibraries = new File(workingDirectory, "lib" + PlatformUtils.SEP + "python.zip");
File nodeBoxLibraries = new File(workingDirectory, "lib" + PlatformUtils.SEP + "nodeboxlibs.zip");
Py.getSystemState().path.add(new PyString(pythonLibraries.getAbsolutePath()));
Py.getSystemState().path.add(new PyString(nodeBoxLibraries.getAbsolutePath()));
// This folder contains unarchived NodeBox libraries.
// Only used in development.
File developmentLibraries = new File("src/python");
Py.getSystemState().path.add(new PyString(developmentLibraries.getAbsolutePath()));
// Add the user's Python directory.
Py.getSystemState().path.add(new PyString(PlatformUtils.getUserPythonDirectory().getAbsolutePath()));
}
}