scalasbtjupytersbt-pluginammonite

How to reuse Ammonite REPL's sc files in a sbt project?


I have some reusable Ammonite REPL's sc files that were used in some Jupyter Scala notebooks.

Now I am creating a standalone application built from sbt. I hope I can reuse these existing sc files in the sbt project.

Is it possible to share these sc files for both Jupyter Scala/Ammonite REPL and sbt projects? How to make scala sources and sc files compile together?


Solution

  • I created Import.scala, a Scala compiler plugin that enables magic imports.

    With the help of Import.scala, code snippets in a .sc file can be loaded into Scala source file in a sbt project with the same syntax as Ammonite or Jupyter Scala:

    Given a MyScript.sc file.

    // MyScript.sc
    val elite = 31337
    

    Magic import it in another file.

    import $file.MyScript
    

    It works.

    assert(MyScript.elite == 31337)