Skip to content

Commit

Permalink
* Synchronize cachePackage() and prevent repeated package caching …
Browse files Browse the repository at this point in the history
…in all presets (pull #1071)
  • Loading branch information
HannesWell authored Aug 23, 2021
1 parent 6451db0 commit 6c2e0a1
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 18 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@

* Synchronize `cachePackage()` and prevent repeated package caching in all presets ([pull #1071](https://github.com/bytedeco/javacpp-presets/pull/1071))
* Build FFmpeg with VA-API enabled and bundle its libraries to avoid loading issues ([issue bytedeco/javacv#1188](https://github.com/bytedeco/javacv/issues/1188))
* Upgrade presets for Arrow 5.0.0, DNNL 2.3.2, SciPy 1.7.1, TensorFlow Lite 2.6.0, DepthAI 2.9.0, ONNX 1.10.1, ONNX Runtime 1.8.2, and their dependencies

Expand Down
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 File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/cpython/" + Loader.getPlatform())} and monkey patches files accordingly. */
public static File cachePackage() throws IOException {
public static synchronized 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,6 +251,7 @@ public static File cachePackage() throws IOException {
}
}
}
packageFile = pythonFile;
return pythonFile;
}

Expand Down
10 changes: 8 additions & 2 deletions gym/src/main/java/org/bytedeco/gym/presets/gym.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,15 @@
public class gym {
static { Loader.checkVersion("org.bytedeco", "gym"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/gym/python/")}. */
public static File cachePackage() throws IOException {
return Loader.cacheResource("/org/bytedeco/gym/python/");
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
packageFile = Loader.cacheResource("/org/bytedeco/gym/python/");
return packageFile;
}

/** Returns {@code {opencv_python3.cachePackages(), scipy.cachePackages(), gym.cachePackage()}}. */
Expand Down
10 changes: 8 additions & 2 deletions llvm/src/main/java/org/bytedeco/llvm/presets/LLVM.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,15 @@
public class LLVM implements InfoMapper {
static { Loader.checkVersion("org.bytedeco", "llvm"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/llvm/" + Loader.getPlatform())}. */
public static File cachePackage() throws IOException {
return Loader.cacheResource("/org/bytedeco/llvm/" + Loader.getPlatform());
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
packageFile = Loader.cacheResource("/org/bytedeco/llvm/" + Loader.getPlatform());
return packageFile;
}

public void map(InfoMap infoMap) {
Expand Down
10 changes: 8 additions & 2 deletions numpy/src/main/java/org/bytedeco/numpy/presets/numpy.java
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@
public class numpy implements InfoMapper {
static { Loader.checkVersion("org.bytedeco", "numpy"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/numpy/" + Loader.getPlatform() + "/python/")}. */
public static File cachePackage() throws IOException {
return Loader.cacheResource("/org/bytedeco/numpy/" + Loader.getPlatform() + "/python/");
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
packageFile = Loader.cacheResource("/org/bytedeco/numpy/" + Loader.getPlatform() + "/python/");
return packageFile;
}

/** Returns {@code {python.cachePackages(), numpy.cachePackage()}}. */
Expand Down
11 changes: 8 additions & 3 deletions opencv/src/main/java/org/bytedeco/opencv/opencv_python3.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,17 +76,22 @@
public class opencv_python3 {
static { Loader.load(); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/opencv/" + Loader.getPlatform() + extension + "/python/")}. */
public static File cachePackage() throws IOException {
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
Loader.load(org.bytedeco.cpython.global.python.class);
String path = Loader.load(opencv_core.class);
if (path != null) {
path = path.replace(File.separatorChar, '/');
int i = path.indexOf("/org/bytedeco/opencv/" + Loader.getPlatform());
int j = path.lastIndexOf("/");
return Loader.cacheResource(path.substring(i, j) + "/python/");
packageFile = Loader.cacheResource(path.substring(i, j) + "/python/");
}
return null;
return packageFile;
}

/** Returns {@code {numpy.cachePackages(), opencv.cachePackage()}}. */
Expand Down
10 changes: 8 additions & 2 deletions scipy/src/main/java/org/bytedeco/scipy/presets/scipy.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,16 @@
public class scipy {
static { Loader.checkVersion("org.bytedeco", "scipy"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/scipy/" + Loader.getPlatform() + "/python/")}. */
public static File cachePackage() throws IOException {
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
Loader.load(scipy.class);
return Loader.cacheResource("/org/bytedeco/scipy/" + Loader.getPlatform() + "/python/");
packageFile = Loader.cacheResource("/org/bytedeco/scipy/" + Loader.getPlatform() + "/python/");
return packageFile;
}

/** Returns {@code {numpy.cachePackages(), scipy.cachePackage()}}. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -430,17 +430,22 @@
public class tensorflow implements BuildEnabled, LoadEnabled, InfoMapper {
static { Loader.checkVersion("org.bytedeco", "tensorflow"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/tensorflow/" + Loader.getPlatform() + extension + "/python/")}. */
public static File cachePackage() throws IOException {
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
Loader.load(org.bytedeco.cpython.global.python.class);
String path = Loader.load(tensorflow.class);
if (path != null) {
path = path.replace(File.separatorChar, '/');
int i = path.indexOf("/org/bytedeco/tensorflow/" + Loader.getPlatform());
int j = path.lastIndexOf("/");
return Loader.cacheResource(path.substring(i, j) + "/python/");
packageFile = Loader.cacheResource(path.substring(i, j) + "/python/");
}
return null;
return packageFile;
}

/** Returns {@code {numpy.cachePackages(), tensorflow.cachePackage()}}. */
Expand Down
11 changes: 8 additions & 3 deletions tvm/src/main/java/org/bytedeco/tvm/presets/tvm.java
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,13 @@
public class tvm {
static { Loader.checkVersion("org.bytedeco", "tvm"); }

private static File packageFile = null;

/** Returns {@code Loader.cacheResource("/org/bytedeco/" + Loader.getPlatform() + extension + "/tvm/python/")}. */
public static File cachePackage() throws IOException {
public static synchronized File cachePackage() throws IOException {
if (packageFile != null) {
return packageFile;
}
Loader.load(org.bytedeco.cpython.global.python.class);
String path = Loader.load(tvm.class);
if (path != null) {
Expand All @@ -72,9 +77,9 @@ public static File cachePackage() throws IOException {
int j = path.lastIndexOf("/");
File f = Loader.cacheResource(path.substring(i, j) + "/python/");
Loader.load(tvm_runtime.class);
return f;
packageFile = f;
}
return null;
return packageFile;
}

/** Returns {@code {scipy.cachePackages(), tvm.cachePackage()}}. */
Expand Down

0 comments on commit 6c2e0a1

Please sign in to comment.