Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More custom directive tweaks #1196

Merged
merged 2 commits into from
Jul 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,8 @@ object Launcher extends CaseApp[LauncherOptions] {
msgFileArgs,
noExecuteInputArgs,
optionsArgs,
options.kernelOptions
options.kernelOptions,
params0.kernelOptions
)

(proc, scalaVersion, jvmIdOpt)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ final case class LauncherOptions(
b ++= Seq(s"--silent-imports=$value")
for (value <- useNotebookCoursierLogger)
b ++= Seq(s"--use-notebook-coursier-logger=$value")
for (group <- customDirectiveGroup.map(_.split(":", 2)).collect { case Array(k, _) => k })
b ++= Seq(s"--launcher-directive-group=$group")
b.result()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import almond.internals.{
import almond.interpreter.ExecuteResult
import almond.interpreter.api.{CommHandler, DisplayData, OutputHandler}
import almond.interpreter.input.InputManager
import almond.launcher.directives.LauncherParameters
import almond.launcher.directives.{CustomGroup, LauncherParameters}
import almond.logger.LoggerContext
import ammonite.compiler.Parsers
import ammonite.repl.api.History
Expand Down Expand Up @@ -49,11 +49,27 @@ final class Execute(
useThreadInterrupt: Boolean,
initialCellCount: Int,
enableExitHack: Boolean,
ignoreLauncherDirectivesIn: Set[String]
ignoreLauncherDirectivesIn: Set[String],
launcherDirectiveGroups: Seq[CustomGroup]
) {

private val handlers = HasKernelOptions.handlers ++
LauncherParameters.handlers.mapDirectives(_.ignoredDirective)
LauncherParameters.handlers.mapDirectives(_.ignoredDirective).addCustomHandler { key =>
launcherDirectiveGroups.find(_.matches(key)).map { group =>
new DirectiveHandler[HasKernelOptions] {
def name = s"custom group ${group.prefix}"
def description = s"custom group ${group.prefix}"
def usage = s"//> ${group.prefix}..."
def keys = Seq(key)
def handleValues(scopedDirective: ScopedDirective)
: Either[DirectiveException, ProcessedDirective[HasKernelOptions]] =
Right(ProcessedDirective(
Some(HasKernelOptions.IgnoredDirectives(Seq(IgnoredDirective(scopedDirective)))),
Nil
))
}
}
}

private val log = logCtx(getClass)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,8 @@ final class ScalaInterpreter(
params.useThreadInterrupt,
params.initialCellCount,
enableExitHack = params.compileOnly,
ignoreLauncherDirectivesIn = params.ignoreLauncherDirectivesIn
ignoreLauncherDirectivesIn = params.ignoreLauncherDirectivesIn,
launcherDirectiveGroups = params.launcherDirectiveGroups
)

val sessApi = new SessionApiImpl(frames0)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package almond
import java.nio.file.Path

import almond.directives.KernelOptions
import almond.launcher.directives.CustomGroup
import almond.protocol.KernelInfo
import ammonite.compiler.iface.CodeWrapper
import ammonite.compiler.CodeClassWrapper
Expand Down Expand Up @@ -44,5 +45,6 @@ final case class ScalaInterpreterParams(
extraClassPath: List[os.Path] = Nil,
initialCellCount: Int = 0,
upfrontKernelOptions: KernelOptions = KernelOptions(),
ignoreLauncherDirectivesIn: Set[String] = Set.empty
ignoreLauncherDirectivesIn: Set[String] = Set.empty,
launcherDirectiveGroups: Seq[CustomGroup] = Nil
)
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,11 @@ final case class Options(

@HelpMessage("Do warn users about launcher directives for incoming messages with the passed ids")
@Hidden
ignoreLauncherDirectivesIn: List[String] = Nil
ignoreLauncherDirectivesIn: List[String] = Nil,

@HelpMessage("Pass launcher directive groups with this option. These directives will be either ignored (see --ignore-launcher-directives-in), or trigger an unused directive warning")
@Hidden
launcherDirectiveGroup: List[String] = Nil
) {
// format: on

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import almond.directives.KernelOptions
import almond.interpreter.messagehandlers.MessageHandler
import almond.kernel.{Kernel, KernelThreads}
import almond.kernel.install.Install
import almond.launcher.directives.CustomGroup
import almond.logger.{Level, LoggerContext}
import almond.util.ThreadUtil.singleThreadedExecutionContext
import caseapp._
Expand Down Expand Up @@ -192,7 +193,8 @@ object ScalaKernel extends CaseApp[Options] {
},
initialCellCount = options.initialCellCount.getOrElse(0),
upfrontKernelOptions = kernelOptionsFromJson,
ignoreLauncherDirectivesIn = options.ignoreLauncherDirectivesIn.toSet
ignoreLauncherDirectivesIn = options.ignoreLauncherDirectivesIn.toSet,
launcherDirectiveGroups = options.launcherDirectiveGroup.map(CustomGroup(_, ""))
),
logCtx = logCtx
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ final case class LauncherParameters(
javaOptions: Seq[String] = Nil,
scala: Option[String] = None,
javaCmd: Option[Seq[String]] = None,
kernelOptions: Seq[String] = Nil,
customDirectives: Seq[(CustomGroup, String, Seq[String])] = Nil
) {
import LauncherParameters._
Expand All @@ -21,6 +22,7 @@ final case class LauncherParameters(
javaOptions ++ other.javaOptions,
scala.orElse(other.scala),
javaCmd.orElse(other.javaCmd),
kernelOptions ++ other.kernelOptions,
customDirectives = customDirectives ++ other.customDirectives
)

Expand Down Expand Up @@ -109,21 +111,24 @@ object LauncherParameters {
jvm: Option[String] = None,
javaOptions: Seq[String] = Nil,
scala: Option[String] = None,
javaCmd: Option[Seq[String]] = None
javaCmd: Option[Seq[String]] = None,
kernelOptions: Seq[String] = Nil
) {
def +(other: AsJson): AsJson =
AsJson(
jvm = jvm.orElse(other.jvm),
javaOptions = javaOptions ++ other.javaOptions,
scala = scala.orElse(other.scala),
javaCmd = javaCmd.orElse(other.javaCmd)
javaCmd = javaCmd.orElse(other.javaCmd),
kernelOptions = kernelOptions ++ other.kernelOptions
)
def params: LauncherParameters =
LauncherParameters(
jvm = jvm,
javaOptions = javaOptions,
scala = scala,
javaCmd = javaCmd
javaCmd = javaCmd,
kernelOptions = kernelOptions
)
}

Expand Down
2 changes: 1 addition & 1 deletion project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ object Deps {
def coursierApi = ivy"io.get-coursier:interface:1.0.18"
def coursierLauncher = ivy"io.get-coursier:coursier-launcher_2.13:${Versions.coursier}"
def dependencyInterface = ivy"io.get-coursier::dependency-interface:0.2.3"
def directiveHandler = ivy"io.github.alexarchambault.scala-cli::directive-handler:0.1.3"
def directiveHandler = ivy"io.github.alexarchambault.scala-cli::directive-handler:0.1.4"
def expecty = ivy"com.eed3si9n.expecty::expecty:0.16.0"
def fansi = ivy"com.lihaoyi::fansi:0.4.0"
def fs2(sv: String) =
Expand Down