Skip to content

Commit

Permalink
Merge pull request #172 from alexarchambault/ammonite-2.3.8-36-1cce53f3
Browse files Browse the repository at this point in the history
Update Ammonite to 2.3.8-36-1cce53f3
  • Loading branch information
alexarchambault committed Feb 19, 2021
2 parents d9ee962 + db804d2 commit d971692
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 39 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
target/
.bsp/
notebooks/
secure/
*.log
Expand Down
1 change: 1 addition & 0 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ lazy val tests = project
generateDependenciesFile,
testSettings,
libraryDependencies ++= Seq(
Deps.ammoniteCompiler.exclude("com.google.guava", "guava"),
Deps.ammoniteRepl.exclude("com.google.guava", "guava"),
Deps.utest
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import java.net.{InetSocketAddress, ServerSocket, URI}
import java.nio.file.Files

import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
import ammonite.repl.api.Frame
import ammonite.util.Frame
import org.eclipse.jetty.server.{Request, Server}
import org.eclipse.jetty.server.handler.AbstractHandler

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ class AmmoniteSparkSessionBuilder
val content = new String(Files.readAllBytes(Paths.get(path)), StandardCharsets.UTF_8)

val extraProps = content
.lines
.linesIterator
.toVector
.filter(!_.startsWith("#"))
.map(_.split("\\s+", 2))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package ammonite.spark.fromammonite

import ammonite.interp.{CodeClassWrapper, CodeWrapper, Interpreter}
import ammonite.compiler.CodeClassWrapper
import ammonite.compiler.iface.CodeWrapper
import ammonite.interp.Interpreter
import ammonite.main.Defaults
import ammonite.ops.{Path, read}
import ammonite.repl._
Expand Down Expand Up @@ -48,6 +50,36 @@ class TestRepl {
)
val storage = new Storage.Folder(tempDir)

private val initialLoader = Thread.currentThread().getContextClassLoader
val frames: Ref[List[Frame]] = Ref(List(Frame.createInitial(initialLoader)))
val sess0 = new SessionApiImpl(frames)

var currentLine = 0
val interp = try {
new Interpreter(
compilerBuilder = ammonite.compiler.CompilerBuilder,
parser = ammonite.compiler.Parsers,
printer = printer0,
storage = storage,
wd = ammonite.ops.pwd,
colors = Ref(Colors.BlackWhite),
verboseOutput = true,
getFrame = () => frames().head,
createFrame = () => { val f = sess0.childFrame(frames().head); frames() = f :: frames(); f },
replCodeWrapper = codeWrapper,
scriptCodeWrapper = codeWrapper,
alreadyLoadedDependencies = Defaults.alreadyLoadedDependencies("ammonite/spark/amm-test-dependencies.txt")
)

}catch{ case e: Throwable =>
println(infoBuffer.mkString)
println(outString)
println(resString)
println(warningBuffer.mkString)
println(errorBuffer.mkString)
throw e
}

val extraBridges = Seq((
"ammonite.repl.ReplBridge",
"repl",
Expand All @@ -63,8 +95,7 @@ class TestRepl {
def history = new History(Vector())
val colors = Ref(Colors.BlackWhite)
def newCompiler() = interp.compilerManager.init(force = true)
def compiler = interp.compilerManager.compiler.compiler
def interactiveCompiler = interp.compilerManager.pressy.compiler
def _compilerManager = interp.compilerManager
def fullImports = interp.predefImports ++ imports
def imports = interp.frameImports
def usedEarlierDefinitions = interp.frameUsedEarlierDefinitions
Expand All @@ -89,34 +120,6 @@ class TestRepl {
}
))

private val initialLoader = Thread.currentThread().getContextClassLoader
val frames: Ref[List[Frame]] = Ref(List(Frame.createInitial(initialLoader)))
val sess0 = new SessionApiImpl(frames)

var currentLine = 0
val interp = try {
new Interpreter(
printer = printer0,
storage = storage,
wd = ammonite.ops.pwd,
colors = Ref(Colors.BlackWhite),
verboseOutput = true,
getFrame = () => frames().head,
createFrame = () => { val f = sess0.childFrame(frames().head); frames() = f :: frames(); f },
replCodeWrapper = codeWrapper,
scriptCodeWrapper = codeWrapper,
alreadyLoadedDependencies = Defaults.alreadyLoadedDependencies("ammonite/spark/amm-test-dependencies.txt")
)

}catch{ case e: Throwable =>
println(infoBuffer.mkString)
println(outString)
println(resString)
println(warningBuffer.mkString)
println(errorBuffer.mkString)
throw e
}

val basePredefs =
if (predef._1.isEmpty) Nil
else Seq(PredefInfo(Name("testPredef"), predef._1, false, predef._2))
Expand Down Expand Up @@ -144,7 +147,7 @@ class TestRepl {
def session(sess: String): Unit = {
// Remove the margin from the block and break
// it into blank-line-delimited steps
val margin = sess.lines.filter(_.trim != "").map(_.takeWhile(_ == ' ').length).min
val margin = sess.linesIterator.filter(_.trim != "").map(_.takeWhile(_ == ' ').length).min
// Strip margin & whitespace

val steps = sess.replace(
Expand All @@ -155,7 +158,7 @@ class TestRepl {
// Break the step into the command lines, starting with @,
// and the result lines
val (cmdLines, resultLines) =
step.lines.toArray.map(_.drop(margin)).partition(_.startsWith("@"))
step.linesIterator.toArray.map(_.drop(margin)).partition(_.startsWith("@"))

val commandText = cmdLines.map(_.stripPrefix("@ ")).toVector

Expand All @@ -166,7 +169,7 @@ class TestRepl {
// ...except for the empty 0-line fragment, and the entire fragment,
// both of which are complete.
for (incomplete <- commandText.inits.toSeq.drop(1).dropRight(1)){
assert(ammonite.interp.Parsers.split(incomplete.mkString(Util.newLine)).isEmpty)
assert(ammonite.compiler.Parsers.split(incomplete.mkString(Util.newLine)).isEmpty)
}

// Finally, actually run the complete command text through the
Expand Down Expand Up @@ -211,7 +214,7 @@ class TestRepl {
case Res.Success(str) =>
// Strip trailing whitespace
def normalize(s: String) =
s.lines
s.linesIterator
.map(_.replaceAll(" *$", ""))
.mkString(Util.newLine)
.trim()
Expand Down Expand Up @@ -256,7 +259,11 @@ class TestRepl {
warningBuffer.clear()
errorBuffer.clear()
infoBuffer.clear()
val splitted = ammonite.interp.Parsers.split(input).get.get.value
val splitted = ammonite.compiler.Parsers.split(input) match {
case None => sys.error(s"No result when splitting input '$input'")
case Some(Left(error)) => sys.error(s"Error when splitting input '$input': $error")
case Some(Right(stmts)) => stmts
}
val processed = interp.processLine(
input,
splitted,
Expand Down
3 changes: 2 additions & 1 deletion project/Deps.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import sbt.Keys._

object Deps {

private def ammoniteVersion = "2.3.8-4-88785969"
private def ammoniteVersion = "2.3.8-36-1cce53f3"
def ammoniteCompiler = ("com.lihaoyi" % "ammonite-compiler" % ammoniteVersion).cross(CrossVersion.full)
def ammoniteReplApi = ("com.lihaoyi" % "ammonite-repl-api" % ammoniteVersion).cross(CrossVersion.full)
def ammoniteRepl = ("com.lihaoyi" % "ammonite-repl" % ammoniteVersion).cross(CrossVersion.full)

Expand Down

0 comments on commit d971692

Please sign in to comment.