From 7c7f9db097e9f1ff45e137546cabe16b0ed9c78d Mon Sep 17 00:00:00 2001 From: agibsonccc Date: Fri, 19 Mar 2021 16:48:25 +0900 Subject: [PATCH] Fix classpathresource for python script --- python4j/python4j-core/pom.xml | 5 +++++ .../src/main/java/org/nd4j/python4j/PythonExecutioner.java | 6 +++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/python4j/python4j-core/pom.xml b/python4j/python4j-core/pom.xml index 4ce5a3bcd..0fc3e096f 100644 --- a/python4j/python4j-core/pom.xml +++ b/python4j/python4j-core/pom.xml @@ -50,6 +50,11 @@ + + org.nd4j + nd4j-common + ${project.version} + diff --git a/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java index 8db2b5b7a..3ae25735d 100644 --- a/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java +++ b/python4j/python4j-core/src/main/java/org/nd4j/python4j/PythonExecutioner.java @@ -34,6 +34,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import org.apache.commons.io.IOUtils; import org.bytedeco.cpython.global.python; +import org.nd4j.common.io.ClassPathResource; import static org.bytedeco.cpython.global.python.*; import static org.bytedeco.cpython.helper.python.Py_SetPath; @@ -182,9 +183,8 @@ public class PythonExecutioner { private static String getWrappedCode(String code) { - - try (InputStream is = PythonExecutioner.class - .getResourceAsStream("org/nd4j/python4j/pythonexec/pythonexec.py")) { + ClassPathResource resource = new ClassPathResource("org/nd4j/python4j/pythonexec/pythonexec.py"); + try (InputStream is = resource.getInputStream()) { String base = IOUtils.toString(is, StandardCharsets.UTF_8); String indentedCode = " " + code.replace("\n", "\n "); String out = base.replace(" pass", indentedCode);