-
Notifications
You must be signed in to change notification settings - Fork 830
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
90089fa
commit 987c7c4
Showing
44 changed files
with
426 additions
and
317 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
addSbtPlugin("org.scalastyle" %% "scalastyle-sbt-plugin" % "1.0.0") | ||
addSbtPlugin("com.eed3si9n" % "sbt-unidoc" % "0.4.2") | ||
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.9.0") |
82 changes: 82 additions & 0 deletions
82
src/codegen/scala/com/microsoft/ml/spark/codegen/CodeGen.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// Copyright (C) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in project root for information. | ||
|
||
package com.microsoft.ml.spark.codegen | ||
|
||
import java.io.File | ||
|
||
import com.microsoft.ml.spark.codegen.Config._ | ||
import com.microsoft.ml.spark.codegen.DocGen._ | ||
import com.microsoft.ml.spark.codegen.WrapperClassDoc._ | ||
import com.microsoft.ml.spark.core.env.FileUtilities._ | ||
import org.apache.commons.io.FileUtils | ||
import org.apache.commons.io.FilenameUtils._ | ||
|
||
object CodeGen { | ||
|
||
def generateArtifacts(): Unit = { | ||
println( | ||
s"""|Running code generation with config: | ||
| topDir: $topDir | ||
| packageDir: $packageDir | ||
| pySrcDir: $pySrcDir | ||
| pyTestDir: $pyTestDir | ||
| pyDocDir: $pyDocDir | ||
| rsrcDir: $rSrcDir | ||
| tmpDocDir: $tmpDocDir """.stripMargin) | ||
|
||
println("Creating temp folders") | ||
if (generatedDir.exists()) FileUtils.forceDelete(generatedDir) | ||
|
||
println("Generating python APIs") | ||
PySparkWrapperGenerator() | ||
println("Generating R APIs") | ||
SparklyRWrapperGenerator(version) | ||
println("Generating .rst files for the Python APIs documentation") | ||
genRstFiles() | ||
|
||
def toDir(f: File): File = new File(f, File.separator) | ||
|
||
//writeFile(new File(pySrcDir, "__init__.py"), packageHelp("")) | ||
FileUtils.copyDirectoryToDirectory(toDir(pySrcOverrideDir), toDir(pySrcDir)) | ||
FileUtils.copyDirectoryToDirectory(toDir(pyTestOverrideDir), toDir(pyTestDir)) | ||
makeInitFiles() | ||
|
||
// build init file | ||
// package python+r zip files | ||
// zipFolder(pyDir, pyZipFile) | ||
rPackageDir.mkdirs() | ||
zipFolder(rSrcDir, new File(rPackageDir, s"mmlspark-$version.zip")) | ||
|
||
//FileUtils.forceDelete(rDir) | ||
// leave the python source files, so they will be included in the super-jar | ||
// FileUtils.forceDelete(pyDir) | ||
// delete the text files with the Python Class descriptions - truly temporary | ||
// FileUtils.forceDelete(tmpDocDir) | ||
} | ||
|
||
private def allTopLevelFiles(dir: File, pred: (File => Boolean) = null): Array[File] = { | ||
def loop(dir: File): Array[File] = { | ||
val (dirs, files) = dir.listFiles.sorted.partition(_.isDirectory) | ||
if (pred == null) files else files.filter(pred) | ||
} | ||
loop(dir) | ||
} | ||
|
||
private def makeInitFiles(packageFolder: String = ""): Unit = { | ||
val dir = new File(new File(pySrcDir,"mmlspark"), packageFolder) | ||
val packageString = if (packageFolder != "") packageFolder.replace("/",".") else "" | ||
val importStrings = | ||
allTopLevelFiles(dir, f => "^[a-zA-Z]\\w*[.]py$".r.findFirstIn(f.getName).isDefined) | ||
.map(f => s"from mmlspark$packageString.${getBaseName(f.getName)} import *\n").mkString("") | ||
writeFile(new File(dir, "__init__.py"), packageHelp(importStrings)) | ||
dir.listFiles().filter(_.isDirectory).foreach(f => | ||
makeInitFiles(packageFolder +"/" + f.getName) | ||
) | ||
} | ||
|
||
def main(args: Array[String]): Unit = { | ||
generateArtifacts() | ||
} | ||
|
||
} |
48 changes: 48 additions & 0 deletions
48
src/codegen/scala/com/microsoft/ml/spark/codegen/CodegenConfig.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
// Copyright (C) Microsoft Corporation. All rights reserved. | ||
// Licensed under the MIT License. See LICENSE in project root for information. | ||
|
||
package com.microsoft.ml.spark.codegen | ||
|
||
import com.microsoft.ml.spark.core.env.FileUtilities._ | ||
import com.microsoft.ml.spark.build.BuildInfo | ||
|
||
object Config { | ||
val debugMode = sys.env.getOrElse("DEBUGMODE", "").trim.toLowerCase == "true" | ||
|
||
val topDir = BuildInfo.baseDirectory | ||
val version = BuildInfo.version | ||
val targetDir = new File(topDir, "target/scala-2.11") | ||
val scalaSrcDir = "src/main/scala" | ||
|
||
val generatedDir = new File(targetDir, "generated") | ||
val packageDir = new File(generatedDir, "package") | ||
val srcDir = new File(generatedDir, "src") | ||
val testDir = new File(generatedDir, "test") | ||
val docDir = new File(generatedDir, "doc") | ||
|
||
//Python Codegen Constant | ||
val pySrcDir = new File(srcDir, "python") | ||
val pyPackageDir = new File(packageDir, "python") | ||
val pyTestDir = new File(testDir, "python") | ||
val pyDocDir = new File(docDir, "python") | ||
val pySrcOverrideDir = new File(topDir, "src/main/python") | ||
val pyTestOverrideDir = new File(topDir, "src/test/python") | ||
val tmpDocDir = new File(pyDocDir, "tmpDoc") | ||
|
||
//R Codegen Constants | ||
val rSrcDir = new File(srcDir, "R") | ||
val sparklyRNamespacePath = new File(rSrcDir, "NAMESPACE") | ||
val rPackageDir = new File(packageDir, "R") | ||
val rTestDir = new File(testDir, "R") | ||
val rSrcOverrideDir = new File(topDir, "src/main/R") | ||
//val rPackageFile = new File(rPackageDir, s"mmlspark-$mmlVer.zip") | ||
|
||
val internalPrefix = "_" | ||
val scopeDepth = " " * 4 | ||
|
||
val copyrightLines = | ||
s"""|# Copyright (C) Microsoft Corporation. All rights reserved. | ||
|# Licensed under the MIT License. See LICENSE in project root for information. | ||
|""".stripMargin | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
Oops, something went wrong.