Skip to content

Commit

Permalink
No more "???" in launcher kernel info
Browse files Browse the repository at this point in the history
  • Loading branch information
alexarchambault committed Jul 6, 2023
1 parent 8a6687e commit 9194e87
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
1 change: 1 addition & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ trait Launcher extends AlmondSimpleModule with BootstrapLauncher with PropertyFi
}
Seq(
"kernel-main-class" -> mainClass,
"ammonite-version" -> Versions.ammonite,
"default-scala212-version" -> ScalaVersions.scala212,
"default-scala213-version" -> ScalaVersions.scala213,
"default-scala-version" -> ScalaVersions.scala3Latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,16 +41,7 @@ object Launcher extends CaseApp[LauncherOptions] {
logCtx: LoggerContext
): (os.proc, String, Option[String]) = {

val requestedScalaVersion = params0.scala
.orElse(options.scala.map(_.trim).filter(_.nonEmpty))
.getOrElse(Properties.defaultScalaVersion)

val scalaVersion = requestedScalaVersion match {
case "2.12" => Properties.defaultScala212Version
case "2" | "2.13" => Properties.defaultScala213Version
case "3" => Properties.defaultScalaVersion
case _ => requestedScalaVersion
}
val (scalaVersion, _) = LauncherInterpreter.computeScalaVersion(params0, options)

def content(entries: Seq[(coursierapi.Artifact, File)]): ClassLoaderContent = {
val entries0 = entries.map {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,27 @@ class LauncherInterpreter(
options: LauncherOptions
) extends Interpreter {

def kernelInfo(): KernelInfo =
def kernelInfo(): KernelInfo = {
val (sv, svOrigin) = LauncherInterpreter.computeScalaVersion(params, options)
KernelInfo(
implementation = "scala",
implementation_version = "???",
implementation_version = Properties.version,
language_info = KernelInfo.LanguageInfo(
name = "scala",
version = "???",
version = Properties.version,
mimetype = "text/x-scala",
file_extension = ".sc",
nbconvert_exporter = "script",
codemirror_mode = Some("text/x-scala")
),
banner =
s"""Almond ${"???"}
|Ammonite ${"???"}
|${"???"}
|Java ${"???"}""".stripMargin, // +
s"""Almond ${Properties.version}
|Ammonite ${Properties.ammoniteVersion}
|Scala $sv (from $svOrigin)""".stripMargin, // +
// params.extraBannerOpt.fold("")("\n\n" + _),
help_links = None // Some(params.extraLinks.toList).filter(_.nonEmpty)
)
}

var kernelOptions = KernelOptions()
var params = LauncherParameters()
Expand Down Expand Up @@ -226,4 +227,21 @@ object LauncherInterpreter {
fansi.Attrs.Empty
)
}

def computeScalaVersion(
params0: LauncherParameters,
options: LauncherOptions
): (String, String) = {

val requestedScalaVersion = params0.scala.map((_, "directive"))
.orElse(options.scala.map(_.trim).filter(_.nonEmpty).map((_, "command-line")))
.getOrElse((Properties.defaultScalaVersion, "default"))

requestedScalaVersion._1 match {
case "2.12" => (Properties.defaultScala212Version, requestedScalaVersion._2)
case "2" | "2.13" => (Properties.defaultScala213Version, requestedScalaVersion._2)
case "3" => (Properties.defaultScalaVersion, requestedScalaVersion._2)
case _ => requestedScalaVersion
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ object Properties {
lazy val version = prop("version")
lazy val commitHash = prop("commit-hash")

lazy val ammoniteVersion = prop("ammonite-version")

lazy val kernelMainClass = prop("kernel-main-class")
lazy val defaultScalaVersion = prop("default-scala-version")
lazy val defaultScala212Version = prop("default-scala212-version")
Expand Down

0 comments on commit 9194e87

Please sign in to comment.