Skip to content

Commit

Permalink
[CPython] prevent repeated package caching
Browse files Browse the repository at this point in the history
  • Loading branch information
HannesWell committed Aug 20, 2021
1 parent 6451db0 commit 2816d66
Showing 1 changed file with 6 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,13 @@
public class python implements InfoMapper {
static { Loader.checkVersion("org.bytedeco", "cpython"); }

private static volatile File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/cpython/" + Loader.getPlatform())} and monkey patches files accordingly. */
public static File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
File pythonFile = Loader.cacheResource("/org/bytedeco/cpython/" + Loader.getPlatform());
File configDir = new File(pythonFile, "lib/python3.9/");
if (configDir.exists()) {
Expand Down Expand Up @@ -246,7 +251,7 @@ public static File cachePackage() throws IOException {
}
}
}
return pythonFile;
return packageFile = pythonFile;
}

/** Returns {@code {f, new File(f, "site-packages"), new File(f, "python3.9"), new File(f, "python3.9/lib-dynload"), new File(f, "python3.9/site-packages")}} where {@code File f = new File(cachePackage(), "lib")}. */
Expand Down

0 comments on commit 2816d66

Please sign in to comment.