Skip to content

Commit

Permalink
[python] Extract .py files recursively
Browse files Browse the repository at this point in the history
  • Loading branch information
frankfliu committed Jun 10, 2023
1 parent b016e5d commit 5173239
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
17 changes: 15 additions & 2 deletions engines/python/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand All @@ -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"
}
8 changes: 7 additions & 1 deletion engines/python/src/main/java/ai/djl/python/engine/PyEnv.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 5173239

Please sign in to comment.