Skip to content

Commit

Permalink
Try to not change contentents of pydev itself (i.e.: don't write $py.…
Browse files Browse the repository at this point in the history
…class files and save jython cache dir in user directory).
  • Loading branch information
fabioz committed Mar 12, 2023
1 parent 9ed14d8 commit 0fc4c97
Showing 1 changed file with 36 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
import org.python.core.Options;
import org.python.core.PyClass;
import org.python.core.PyException;
import org.python.core.PyJavaType;
Expand Down Expand Up @@ -237,6 +238,29 @@ public void start(BundleContext context) throws Exception {

private static final Object lock = new Object();

public static File getDefaultJythonCacheDir() {
String userHome = System.getProperty("user.home");
if (userHome != null) {
try {
File f = new File(userHome);
if (f.isDirectory()) {
f = new File(f, ".pydev");
if (!f.exists()) {
f.mkdirs();
}
f = new File(f, "jycachedir");
if (!f.exists()) {
f.mkdirs();
}
return f;
}
} catch (Throwable e) {
Log.log(e);
}
}
return null;
}

private static void setupJython() {
synchronized (lock) {
if (bundles != null && plugin != null) {
Expand All @@ -251,7 +275,18 @@ private static void setupJython() {
AllBundleClassLoader allBundleClassLoader = new AllBundleClassLoader(plugin.getClass()
.getClassLoader());

PySystemState.initialize(System.getProperties(), prop2, new String[0], allBundleClassLoader);
Properties preProperties = new Properties();
Properties sysProperties = System.getProperties();
preProperties.putAll(sysProperties);
if (!preProperties.contains("python.cachedir")) {
File cacheDir = getDefaultJythonCacheDir();
if (cacheDir != null) {
preProperties.put("python.cachedir", cacheDir.toString());
}
}

Options.dont_write_bytecode = true;
PySystemState.initialize(preProperties, prop2, new String[0], allBundleClassLoader);
List<String> packageNames = allBundleClassLoader.setBundlesAndGetPackageNames(bundles);
int size = packageNames.size();
for (int i = 0; i < size; ++i) {
Expand Down

0 comments on commit 0fc4c97

Please sign in to comment.