diff --git a/engines/python/build.gradle b/engines/python/build.gradle index ce831af74..be1c40975 100644 --- a/engines/python/build.gradle +++ b/engines/python/build.gradle @@ -28,8 +28,19 @@ processResources { def propFile = file("${project.buildDir}/classes/java/main/native/lib/python.properties") def sb = new StringBuilder() sb.append("version=${version}\nlibraries=djl_python_engine.py") - for (String name : file("setup/djl_python").list().sort()) { - sb.append(",djl_python/").append(name) + + def list = [] + def dir = file("setup/djl_python") + dir.eachFileRecurse(groovy.io.FileType.FILES) { file -> + if (file.isFile()) { + list.add(dir.relativePath(file)) + } + } + list.sort() + for (String name : list) { + if (!name.contains("__pycache__")) { + sb.append(",djl_python/").append(name) + } } propFile.text = sb.toString() } @@ -46,6 +57,8 @@ clean.doFirst { delete "setup/djl_python.egg-info/" delete "setup/__pycache__/" delete "setup/djl_python/__pycache__/" + delete "setup/djl_python/tests/__pycache__/" + delete "setup/djl_python/scheduler/__pycache__/" delete "src/test/resources/accumulate/__pycache__/" delete System.getProperty("user.home") + "/.djl.ai/python" } diff --git a/engines/python/src/main/java/ai/djl/python/engine/PyEnv.java b/engines/python/src/main/java/ai/djl/python/engine/PyEnv.java index 3142ecdae..ab098c90d 100644 --- a/engines/python/src/main/java/ai/djl/python/engine/PyEnv.java +++ b/engines/python/src/main/java/ai/djl/python/engine/PyEnv.java @@ -102,7 +102,13 @@ static synchronized void init() { if (is == null) { throw new AssertionError("Python engine script not found: " + libPath); } - Files.copy(is, tmp.resolve(file), StandardCopyOption.REPLACE_EXISTING); + Path f = tmp.resolve(file); + Path dir = f.getParent(); + if (dir == null) { + throw new AssertionError("Parent direct cannot be null"); + } + Files.createDirectories(dir); + Files.copy(is, f, StandardCopyOption.REPLACE_EXISTING); } } Utils.moveQuietly(tmp, path);