Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: almond-sh/almond
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: dca237a5de3af9a73709196acf87b27c8d6539ba
Choose a base ref
..
head repository: almond-sh/almond
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 996f315d3ec603e32aa0e40347e12166a587598b
Choose a head ref
Showing with 256 additions and 128 deletions.
  1. +4 −4 .github/workflows/ci.yml
  2. +2 −2 Dockerfile
  3. +1 −1 build.sc
  4. +1 −1 examples/colors.ipynb
  5. +1 −1 examples/displays.ipynb
  6. +1 −1 examples/plotly-scala.ipynb
  7. +1 −1 examples/scalapy-displays.ipynb
  8. +1 −1 examples/test.ipynb
  9. +8 −1 modules/echo/src/main/scala/almond/echo/EchoKernel.scala
  10. +20 −3 modules/echo/src/main/scala/almond/echo/Options.scala
  11. +3 −0 modules/scala/examples/src/test/scala/almond/examples/Examples.scala
  12. +28 −7 modules/scala/integration/src/main/scala/almond/integration/AlmondFunSuite.scala
  13. +5 −3 modules/scala/integration/src/main/scala/almond/integration/KernelLauncher.scala
  14. +8 −1 modules/scala/integration/src/main/scala/almond/integration/KernelTestsDefinitions.scala
  15. +7 −7 modules/scala/integration/src/test/scala/almond/integration/KernelTestsTwoStepStartup213.scala
  16. +6 −2 modules/scala/launcher/src/main/scala/almond/launcher/Launcher.scala
  17. +11 −1 modules/scala/launcher/src/main/scala/almond/launcher/LauncherOptions.scala
  18. +2 −1 modules/scala/scala-interpreter/src/main/scala-2/almond/internals/ScalaInterpreterInspections.scala
  19. +18 −12 modules/scala/scala-interpreter/src/main/scala/almond/ScalaInterpreter.scala
  20. +9 −1 modules/scala/scala-interpreter/src/main/scala/almond/amm/AmmInterpreter.scala
  21. +28 −18 modules/scala/scala-kernel/src/main/scala/almond/Options.scala
  22. +2 −1 modules/scala/scala-kernel/src/main/scala/almond/ScalaKernel.scala
  23. +9 −9 modules/scala/scala-kernel/src/test/scala/almond/ScalafmtTests.scala
  24. +9 −9 modules/scala/test-definitions/src/main/scala/almond/integration/Tests.scala
  25. +6 −3 modules/shared/channels/src/main/scala/almond/channels/Connection.scala
  26. +5 −4 modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqConnection.scala
  27. +1 −1 modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocket.scala
  28. +7 −1 modules/shared/channels/src/main/scala/almond/channels/zeromq/ZeromqSocketImpl.scala
  29. +2 −2 modules/shared/channels/src/test/scala/almond/channels/zeromq/ZeromqConnectionTests.scala
  30. +5 −4 modules/shared/channels/src/test/scala/almond/channels/zeromq/ZeromqSocketTests.scala
  31. +32 −14 modules/shared/kernel/src/main/scala/almond/kernel/Kernel.scala
  32. +13 −11 project/deps.sc
8 changes: 4 additions & 4 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -45,17 +45,17 @@ jobs:
matrix:
OS: [ubuntu-latest]
JDK: [8]
SCALA: [2.12.17, 2.12.18, 2.13.11, 2.13.12, 3.3.0]
SCALA: [2.12.18, 2.12.19, 2.13.12, 2.13.13, 3.3.3]
include:
- OS: windows-latest
JDK: 8
SCALA: 2.13.12
SCALA: 2.13.13
- OS: macos-12
JDK: 8
SCALA: 2.13.12
SCALA: 2.13.13
- OS: ubuntu-latest
JDK: 17
SCALA: 2.12.18
SCALA: 2.12.19
steps:
- name: Don't convert LF to CRLF during checkout
if: runner.os == 'Windows'
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Dockerfile with support for creating images with kernels for multiple Scala versions.
# Expects ALMOND_VERSION and SCALA_VERSIONS to be set as build arg, like this:
# docker build --build-arg ALMOND_VERSION=0.13.11 --build-arg SCALA_VERSIONS="2.12.18 2.13.11" .
# docker build --build-arg ALMOND_VERSION=0.13.11 --build-arg SCALA_VERSIONS="2.12.19 2.13.11" .

# Set LOCAL_IVY=yes to have the contents of ivy-local copied into the image.
# Can be used to create an image with a locally built almond that isn't on maven central yet.
@@ -36,7 +36,7 @@ FROM coursier_base as local_ivy_no
FROM local_ivy_${LOCAL_IVY}
ARG ALMOND_VERSION
# Set to a single Scala version string or list of Scala versions separated by a space.
# i.e SCALA_VERSIONS="2.12.18 2.13.11"
# i.e SCALA_VERSIONS="2.12.19 2.13.11"
ARG SCALA_VERSIONS
USER $NB_UID
COPY scripts/install-kernels.sh .
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
@@ -462,7 +462,7 @@ object scala extends Module {
}

trait Examples extends SbtModule {
private def examplesScalaVersion = "2.12.18"
private def examplesScalaVersion = "2.12.19"
private def baseRepoRoot = os.sub / "out" / "repo"
def scalaVersion = ScalaVersions.scala3Latest
object test extends SbtModuleTests {
2 changes: 1 addition & 1 deletion examples/colors.ipynb
Original file line number Diff line number Diff line change
@@ -69,7 +69,7 @@
"mimetype": "text/x-scala",
"name": "scala",
"nbconvert_exporter": "script",
"version": "2.12.18"
"version": "2.12.19"
}
},
"nbformat": 4,
2 changes: 1 addition & 1 deletion examples/displays.ipynb
Original file line number Diff line number Diff line change
@@ -156,7 +156,7 @@
"mimetype": "text/x-scala",
"name": "scala",
"nbconvert_exporter": "script",
"version": "2.12.18"
"version": "2.12.19"
}
},
"nbformat": 4,
2 changes: 1 addition & 1 deletion examples/plotly-scala.ipynb
Original file line number Diff line number Diff line change
@@ -1974,7 +1974,7 @@
"mimetype": "text/x-scala",
"name": "scala",
"nbconvert_exporter": "script",
"version": "2.12.18"
"version": "2.12.19"
}
},
"nbformat": 4,
2 changes: 1 addition & 1 deletion examples/scalapy-displays.ipynb
Original file line number Diff line number Diff line change
@@ -198,7 +198,7 @@
"mimetype": "text/x-scala",
"name": "scala",
"nbconvert_exporter": "script",
"version": "2.12.18"
"version": "2.12.19"
}
},
"nbformat": 4,
2 changes: 1 addition & 1 deletion examples/test.ipynb
Original file line number Diff line number Diff line change
@@ -40,7 +40,7 @@
"mimetype": "text/x-scala",
"name": "scala",
"nbconvert_exporter": "script",
"version": "2.12.18"
"version": "2.12.19"
}
},
"nbformat": 4,
9 changes: 8 additions & 1 deletion modules/echo/src/main/scala/almond/echo/EchoKernel.scala
Original file line number Diff line number Diff line change
@@ -53,7 +53,14 @@ object EchoKernel extends CaseApp[Options] {

log.debug("Running kernel")
Kernel.create(new EchoInterpreter, interpreterEc, kernelThreads, logCtx)
.flatMap(_.runOnConnectionFile(connectionFile, "echo", zeromqThreads, Nil, autoClose = true))
.flatMap(_.runOnConnectionFile(
connectionFile,
"echo",
zeromqThreads,
Nil,
autoClose = true,
lingerDuration = options.lingerDuration
))
.unsafeRunSync()(IORuntime.global)
}
}
23 changes: 20 additions & 3 deletions modules/echo/src/main/scala/almond/echo/Options.scala
Original file line number Diff line number Diff line change
@@ -4,15 +4,32 @@ import almond.kernel.install.{Options => InstallOptions}
import caseapp.{HelpMessage, Recurse}
import caseapp.core.help.Help
import caseapp.core.parser.Parser
import caseapp.Hidden
import scala.concurrent.duration.{Duration, DurationInt}

// format: off
final case class Options(
connectionFile: Option[String] = None,
@HelpMessage("Log level (one of none, error, warn, info, or debug)")
log: String = "warn",
log: String = "warn",
install: Boolean = false,
@Recurse
installOptions: InstallOptions = InstallOptions()
)
installOptions: InstallOptions = InstallOptions(),

@HelpMessage(
"""Time given to the client to accept ZeroMQ messages before exiting. Parsed with scala.concurrent.duration.Duration, this accepts things like "Inf" or "5 seconds""""
)
@Hidden
linger: Option[String] = None
) {
// format: on

lazy val lingerDuration = linger
.map(_.trim)
.filter(_.nonEmpty)
.map(Duration(_))
.getOrElse(5.seconds)
}

object Options {
implicit lazy val parser: Parser[Options] = Parser.derive
Original file line number Diff line number Diff line change
@@ -2,12 +2,15 @@ package almond.examples

import java.nio.charset.Charset

import scala.concurrent.duration.DurationInt
import scala.util.Properties

class Examples extends munit.FunSuite {

def kernelId = "almond-examples"

override def munitTimeout = 5.minutes

lazy val notebooks = os.list(ExampleProperties.directory)
.filter(_.last.endsWith(".ipynb"))
.filter(os.isFile(_))
Original file line number Diff line number Diff line change
@@ -4,13 +4,20 @@ import munit.{Location, TestOptions}

import java.util.concurrent.atomic.AtomicInteger

import scala.concurrent.duration.DurationInt
import scala.util.control.NonFatal

abstract class AlmondFunSuite extends munit.FunSuite {

def mightRetry: Boolean = false
def mightRetry: Boolean = false
override def munitTimeout = 5.minutes

override def test(options: TestOptions)(body: => Any)(implicit loc: Location): Unit =
override def test(options: TestOptions)(body: => Any)(implicit loc: Location): Unit = {
val className = getClass.getName
val (classNameInit, classNameLast) = {
val a = className.split('.')
(a.init, a.last)
}
super.test(options) {

def runBody(attempt: Int): Any = {
@@ -31,7 +38,9 @@ abstract class AlmondFunSuite extends munit.FunSuite {
if (attempt == 1)
AlmondFunSuite.retriedTestsCount.incrementAndGet()
System.err.println(
s"Attempt $attempt of ${Console.RED}${options.name}${Console.RESET} failed, trying again"
s"Attempt $attempt of ${Console.RED}${classNameInit.mkString(".")}" + "." +
s"${Console.BOLD}$classNameLast${Console.RESET}${Console.RED}" + "." +
s"${Console.BOLD}${options.name}${Console.RESET} failed, trying again"
)
e.printStackTrace(System.err)
runBody(attempt + 1)
@@ -42,7 +51,11 @@ abstract class AlmondFunSuite extends munit.FunSuite {
}

System.err.println()
System.err.println(s"Running ${Console.BLUE}${options.name}${Console.RESET}")
System.err.println(
s"${Console.BLUE}Running ${classNameInit.mkString(".")}" + "." +
s"${Console.BOLD}$classNameLast${Console.RESET}${Console.BLUE}" + "." +
s"${Console.BOLD}${options.name}${Console.RESET}"
)
var success = false
var exOpt = Option.empty[Throwable]
try {
@@ -56,15 +69,23 @@ abstract class AlmondFunSuite extends munit.FunSuite {
}
finally {
if (success)
System.err.println(s"Done: ${Console.CYAN}${options.name}${Console.RESET}")
System.err.println(
s"${Console.CYAN}Done: ${classNameInit.mkString(".")}" + "." +
s"${Console.BOLD}$classNameLast${Console.RESET}${Console.CYAN}" + "." +
s"${Console.BOLD}${options.name}${Console.RESET}"
)
else {
System.err.println(s"Failed: ${Console.RED}${options.name}${Console.RESET}")
System.err.println(
s"${Console.RED}Failed: ${classNameInit.mkString(".")}" + "." +
s"${Console.BOLD}$classNameLast${Console.RESET}${Console.RED}" + "." +
s"${Console.BOLD}${options.name}${Console.RESET}"
)
exOpt.foreach(_.printStackTrace(System.err))
}
System.err.println()
}
}(loc)

}
}

object AlmondFunSuite {
Original file line number Diff line number Diff line change
@@ -275,9 +275,11 @@ class KernelLauncher(
}

def close(): Unit = {
conn.close(partial = false).unsafeRunTimed(2.minutes)(IORuntime.global).getOrElse {
sys.error("Timeout when closing ZeroMQ connections")
}
conn.close(partial = false, lingerDuration = 30.seconds)
.unsafeRunTimed(2.minutes)(IORuntime.global)
.getOrElse {
sys.error("Timeout when closing ZeroMQ connections")
}

if (perTestZeroMqContext) {
val t = stackTracePrinterThread(output)
Original file line number Diff line number Diff line change
@@ -8,6 +8,13 @@ abstract class KernelTestsDefinitions extends AlmondFunSuite {

override def mightRetry = true

lazy val javaMajorVersion = {
val versionString =
sys.props.getOrElse("java.version", sys.error("java.version property not set"))
.stripPrefix("1.") // for Java 8 and below
versionString.takeWhile(_ != '.').toInt
}

test("jvm-repr") {
kernelLauncher.withKernel { implicit runner =>
implicit val sessionId: SessionId = SessionId()
@@ -102,7 +109,7 @@ abstract class KernelTestsDefinitions extends AlmondFunSuite {
}
}

if (kernelLauncher.defaultScalaVersion.startsWith("2."))
if (kernelLauncher.defaultScalaVersion.startsWith("2.") && javaMajorVersion >= 11)
test("inspections") {
kernelLauncher.withKernel { implicit runner =>
implicit val sessionId: SessionId = SessionId()
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
|""".stripMargin,
expectError = true,
stderr =
"""cell2.sc:6: method foo in class Helper is deprecated
"""cmd2.sc:6: method foo in class Helper is deprecated
|val res2_1 = foo()
| ^
|No warnings can be incurred under -Werror.
@@ -63,7 +63,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
|""".stripMargin,
expectError = true,
stderr =
"""cell2.sc:4: method foo in class Helper is deprecated
"""cmd2.sc:4: method foo in class Helper is deprecated
|val res2_1 = foo()
| ^
|No warnings can be incurred under -Werror.
@@ -92,7 +92,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
|""".stripMargin,
expectError = true,
stderr =
"""cell1.sc:7: method foo in class Helper is deprecated
"""cmd1.sc:7: method foo in class Helper is deprecated
|val res1_1 = foo()
| ^
|No warnings can be incurred under -Werror.
@@ -111,7 +111,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
runner.withSession() { implicit session =>

execute(
"""//> using scala "2.12.18"
"""//> using scala "2.12.19"
|//> using option "-Xfatal-warnings"
|""".stripMargin,
""
@@ -127,7 +127,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
|""".stripMargin,
expectError = true,
stderr =
"""cell2.sc:6: method foo in class Helper is deprecated
"""cmd2.sc:6: method foo in class Helper is deprecated
|val res2_1 = foo()
| ^
|No warnings can be incurred under -Xfatal-warnings.
@@ -146,7 +146,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
runner.withSession() { implicit session =>

execute(
"""//> using scala "2.12.18"
"""//> using scala "2.12.19"
|//> using option "-Xfatal-warnings"
|""".stripMargin,
""
@@ -162,7 +162,7 @@ class KernelTestsTwoStepStartup213 extends KernelTestsDefinitions {
|""".stripMargin,
expectError = true,
stderr =
"""cell2.sc:6: method foo in class Helper is deprecated
"""cmd2.sc:6: method foo in class Helper is deprecated
|val res2_1 = foo()
| ^
|No warnings can be incurred under -Xfatal-warnings.
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@ import java.nio.channels.ClosedSelectorException
import scala.concurrent.duration.DurationInt
import scala.jdk.CollectionConverters._
import scala.util.control.NonFatal
import scala.concurrent.duration.Duration

object Launcher extends CaseApp[LauncherOptions] {

@@ -325,7 +326,8 @@ object Launcher extends CaseApp[LauncherOptions] {
"scala",
zeromqThreads,
Nil,
autoClose = false
autoClose = false,
lingerDuration = Duration.Inf // unused here
))
.unsafeRunSync()(IORuntime.global)
val leftoverMessages: Seq[(Channel, RawMessage)] = run.unsafeRunSync()(IORuntime.global)
@@ -410,7 +412,9 @@ object Launcher extends CaseApp[LauncherOptions] {
for (outputHandler <- outputHandlerOpt)
outputHandler.done()

try conn.close(partial = false).unsafeRunSync()(IORuntime.global)
try
conn.close(partial = false, lingerDuration = options.lingerDuration)
.unsafeRunSync()(IORuntime.global)
catch {
case NonFatal(e) =>
throw new Exception(e)
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ import caseapp._

import scala.cli.directivehandler.EitherSequence._
import scala.collection.mutable
import scala.concurrent.duration.{Duration, DurationInt}

// format: off
final case class LauncherOptions(
@@ -34,7 +35,10 @@ final case class LauncherOptions(
quiet: Option[Boolean] = None,
silentImports: Option[Boolean] = None,
useNotebookCoursierLogger: Option[Boolean] = None,
customDirectiveGroup: List[String] = Nil
customDirectiveGroup: List[String] = Nil,
@HelpMessage("Time given to the client to accept ZeroMQ messages before handing over the connections to the kernel. Parsed with scala.concurrent.duration.Duration, this accepts things like \"Inf\" or \"5 seconds\"")
@Hidden
linger: Option[String] = None
) {
// format: on

@@ -91,6 +95,12 @@ final case class LauncherOptions(
groups
}
}

lazy val lingerDuration = linger
.map(_.trim)
.filter(_.nonEmpty)
.map(Duration(_))
.getOrElse(5.seconds)
}

object LauncherOptions {
Loading