org.python.util.ProxyCompiler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jython-slim Show documentation
Show all versions of jython-slim Show documentation
Jython is an implementation of the high-level, dynamic, object-oriented
language Python written in 100% Pure Java, and seamlessly integrated with
the Java platform. It thus allows you to run Python on any Java platform.
package org.python.util;
import java.util.Properties;
import org.python.core.PySystemState;
import org.python.core.RegistryKey;
public class ProxyCompiler {
/**
* Compiles the python file by loading it
*
* FIXME: this is quite hackish right now. It basically starts a whole interpreter and sets
* proxyDebugDirectory as the destination for the compiled proxy class
*
* @param filename python filename to exec
* @param destDir destination directory for the proxy classes
*/
public static void compile(String filename, String destDir) {
Properties props = new Properties(System.getProperties());
props.setProperty(RegistryKey.PYTHON_CACHEDIR_SKIP, "true");
PySystemState.initialize(props, null);
PythonInterpreter interp = new PythonInterpreter();
String origProxyDir = org.python.core.Options.proxyDebugDirectory;
try {
org.python.core.Options.proxyDebugDirectory = destDir;
interp.execfile(filename);
} finally {
org.python.core.Options.proxyDebugDirectory = origProxyDir;
}
}
}