diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/codegen/PyCodegen.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/codegen/PyCodegen.scala index 425d7314f6..b6cbef3a81 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/codegen/PyCodegen.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/codegen/PyCodegen.scala @@ -42,9 +42,15 @@ object PyCodegen { val initFile = new File(dir, "__init__.py") if (packageFolder != "/cognitive"){ if (packageFolder != "") { - writeFile(initFile, conf.packageHelp(importStrings)) + if (initFile.exists()) { + prependToFile(initFile, conf.packageHelp(importStrings)) + } else { + writeFile(initFile, conf.packageHelp(importStrings)) + } } else if (initFile.exists()) { - initFile.delete() + if (initFile.length() == 0) { + initFile.delete() + } } } dir.listFiles().filter(_.isDirectory).foreach(f => diff --git a/core/src/main/scala/com/microsoft/azure/synapse/ml/core/env/FileUtilities.scala b/core/src/main/scala/com/microsoft/azure/synapse/ml/core/env/FileUtilities.scala index baecf3d8bd..544d8bd1db 100644 --- a/core/src/main/scala/com/microsoft/azure/synapse/ml/core/env/FileUtilities.scala +++ b/core/src/main/scala/com/microsoft/azure/synapse/ml/core/env/FileUtilities.scala @@ -61,6 +61,13 @@ object FileUtilities { () } + def prependToFile(file: File, stuff: Any): Unit = { + val existingContent = new String(Files.readAllBytes(file.toPath)) + val newContent = stuff.toString + existingContent + Files.write(file.toPath, newContent.getBytes()) + () + } + def copyFile(from: File, toDir: File, overwrite: Boolean = false): Unit = { Files.copy(from.toPath, new File(toDir, from.getName).toPath, (if (overwrite) Seq(StandardCopyOption.REPLACE_EXISTING)