Where communities thrive

  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
Repo info
  • Jan 30 2019 14:37
    bhaskarmelkani starred lihaoyi/Ammonite
  • Jan 29 2019 04:27
    JYInMyHeart starred lihaoyi/Ammonite
  • Jan 29 2019 04:27
    JYInMyHeart starred lihaoyi/Ammonite
  • Jan 28 2019 15:07
    ishubelko starred lihaoyi/Ammonite
  • Jan 25 2019 22:38
    borissmidt starred lihaoyi/Ammonite
  • Jan 25 2019 17:12

    alexarchambault on 1.6.3


  • Jan 25 2019 17:11

    alexarchambault on master

    1.6.3 (compare)

  • Jan 25 2019 15:48
    alexarchambault commented #923
  • Jan 25 2019 01:15

    lihaoyi on gh-pages

    5ad9ae5538f23cab92ccd8c6b1617d8… (compare)

  • Jan 25 2019 00:50

    alexarchambault on master

    Partly revert 84d48542 (#923) … (compare)

  • Jan 25 2019 00:50
    alexarchambault closed #923
  • Jan 25 2019 00:50
    alexarchambault closed #920
  • Jan 25 2019 00:50
    alexarchambault closed #922
  • Jan 24 2019 23:13
    lihaoyi commented #923
  • Jan 24 2019 22:39
    alexarchambault closed #921
  • Jan 24 2019 22:39
    alexarchambault commented #921
  • Jan 24 2019 22:39
    alexarchambault edited #923
  • Jan 24 2019 22:38
    alexarchambault opened #923
  • Jan 24 2019 22:37
    david-bouyssie commented #919
  • Jan 24 2019 21:33
    nksureshkumar commented #922
Chris Kipp
you should be able to use something like sbt whatDependsOn or even coursier resolve to see what is actually pulling that in

Heya, I'm struggling a bit with multiple ammonite consoles running concurrently, attempting to concurrently modify the fs cache:

java.nio.file.FileAlreadyExistsException: /home/.../.ammonite/rt-11.0.11.jar
        at java.base/sun.nio.fs.UnixCopyFile.copy(UnixCopyFile.java:573)
        at ...
        at io.github.retronym.java9rtexport.Export.rtAt(Export.java:105)
        at ammonite.util.Classpath$.classpath(Classpath.scala:76)
        at ammonite.compiler.CompilerLifecycleManager.init(CompilerLifecycleManager.scala:92)

Is this not supported?

1 reply
Since the switch from "@doc" to "@arg(doc = ", I haven't understood how the doc for a main method is used by amm. The @doc behavior of displaying the description for all the main methods was nice.
Artem Egorkine
Whatever happened to ammonite printing method signatures on tab completion (as mentioned in issue #26) is it hidden behind a flag or completely removed for some reason?
Artem Egorkine
Why does source not work anymore in ammonite 2.4.0?
@ source(source) 
cmd0.sc:1: could not find implicit value for parameter pprinter: pprint.PPrinter
val res0 = source(source)
Compilation Failed
Glen Marchesani
is there a way to have a ammonite script define a function. So ideally I would like a file with something like...
object myplugin extends Plugin {
then to be able to take that .scala file and get back the actual instance of myplugin...
the way I do that now is something more like this... We pass in a Context object so it looks more like this

object myplugin extends Plugin {

with a bit of haranging in the internals to have that work as expected
I guess perhaps a core question is can an ammonite script return a scala instance ? Is there some special way to do that. Or is the context callback method the best way to do that.

@fizzy33 Idk if I get it, but I'm a bit curious, why not use import $file for this?

object BuildingBlocks extends Plugin {
val plugin = BuildingBlocks

Then load it like:

import $file.MyPlugin

Glen Marchesani
so the bigger picture is I have an app that on startup checks a folder for ammonite scripts that is loads and runs. The scripts for the purpose of this example can register plugins with the app. Trying to setup the plugin registration to be a bit simpler. What I really need is the script to return a value OR to give me all the things defined in teh script.
I need to know what is in the script so I/we can auto register everything. What we do now is pass in a context where you explicitly reguister stuff.,
Glen Marchesani
to be clear this is a scala app
Li Haoyi
scripts currently just return themselves; there isn't really extension points to make the script objects implement interfaces, but you can always fish out whatever is defined on them whether manually (as mentioned above) or via reflection (Mill does this)
André Schütz
Hi, one question. Is there a possibility to check unused imports or execute code formatting for ammonite scripts?
Glen Marchesani
thanks @lihaoyi
any chance you can point at mill code that does that ?
Li Haoyi
@faustas I don't believe we support checking unused imports, but running scalafmt might just work right out of the boc
@fizzy33 should be this https://github.com/com-lihaoyi/mill/blob/main/main/core/src/define/Module.scala#L59-L72. Nothing fancy, it's literally just poking at the "Module" object (which in Mill is every static object, including the top-level script wrapper) using good old Java reflection
@eric-bzb did you ever resolve how to use cats-effect inside an ammonite script?
I'm also trying to write something simple with IO that runs perfectly fine in the ammonite repl but hangs halfway when run as a script
Martin Kneissl
Hi, I'm starting with ammonite (again) and keep getting missing implicit pretty printers.
$ amm
Welcome to the Ammonite Repl 2.4.0 (Scala 2.13.6 Java 11.0.11)
kneissl-kneissl@ browse("hello")
cmd0.sc:1: could not find implicit value for parameter pp: pprint.PPrinter
val res0 = browse("hello")
Compilation Failed
1 reply
@emeinhardt unfortunately I never did resolve how to use cats-effect inside an ammonite script, despite it working fine in a repl session. I ended up just not using a script and instead using mill to write a simple app object Main extends IOApp { def run(args: List[Stirng)) = ??? } in main/src/Main.scala. Then using mill -i main.run <arg1> <arg2> . The -i flag in mill is necessary to make things like IO.readLine work as expected.
Glen Marchesani
thanks @lihaoyi I can bootstrap a lot from that :-)
Mahdi Robatipoor
How i can run ammonite on scala 3 ?
Glen Marchesani

@lihaoyi looking through the mill code is a great help thanks. The last piece that I am missing is where in the code is ammonite running the script and returning the objects in the script. So in mill you have

import mill._, scalalib._

object foo extends ScalaModule {
  def scalaVersion = "3.0.2"

Something is evaluating the script seeing there is a foo in there and then extracting the instance out. I can see the reflection stuff you have shared as being highly useful and I think I am just missing how I can get the "foo" out of that ammonite script.

here is my very naive approach

  val runner: Main =
      predefCode = "println(\"running\")",

  val results = runner.runCode("""object Bob { println("running 2"); def foo = 1 }""")

  val results2 = runner.runCode("""println(Bob.toString)""")
which gives cmd0.sc:1: not found: value Bob val res = println(Bob.toString) ^
another way of asking this is if I dig into results I can see there is a "Bob" term in the script but how do I get to access it's actual instance
Glen Marchesani
I guess I could spoon feed this into a repl via an input stream
anywho curious if you recommend a path @lihaoyi
Jesper S.
Can you import a java dependency with ivy?
import $ivy.org.apache.hadoop::hadoop-client:3.3.0` fails with a not found exception not found: https://repo1.maven.org/maven2/org/apache/hadoop/hadoop-client_2.13/3.3.0/hadoop-client_2.13-3.3.0.pom`. It looks like the link tries to find a scala version of the java library.
Tobias Roeser
For Java deps use a single colon before the artifact name
1 reply
Glen Marchesani
@lihaoyi I figured it all out by staring at the mill code, thanks again for your assistance. I can see in MainRunner how a CustomCodeWrapper is used and then in RunScipt the def millSelf = Some(this) that is provided in the CustomCodeWrapper is called to get the actual modeul insance. that is the pattern I needed.
Glen Marchesani
once I have the module instance I am off to the races getting the rest of what I need via plain old java.reflect
Hi all, Is there a straightforward way of a creating a JAR from a given Ammonite script with $ivy dependencies?
Thomas Dickerson
is there a standard predef somewhere that I'm missing if I just downloaded the bootstrap script?
I'm seeing:
Welcome to the Ammonite Repl 2.4.0 (Scala 2.13.6 Java 1.8.0_121)
@ wd
cmd0.sc:1: not found: value wd
val res0 = wd
Compilation Failed
Thomas Dickerson
hmmm, found the example predef, but can't seem to configure my prompt?
thomas-Downloads@ repl.colors().prompt() = fansi.Attrs.Empty
cmd0.sc:1: value colors in trait FullReplAPI cannot be accessed as a member of ammonite.repl.FullReplAPI from object cmd0 in package $sess
 Access to protected value colors not permitted because
 enclosing object cmd0 in package $sess is not a subclass of
 trait FullReplAPI in package repl where target is defined
val res0 = repl.colors().prompt() = fansi.Attrs.Empty
Compilation Failed
Thomas Dickerson
okay, got that figured out, but can't get my colors to actually apply.
@lihaoyi - tried following suggested setup in #399 and I can (a) construct a colored string, (b) reset the prompt color
but I can't actually get the prompt to use the colors in the string
I have this snippet:
interp.colors().prompt() = fansi.Color.Reset
  val hostname:String = (%%hostname("-s")).out.string.trim
  val Home = Path(sys.props("user.home"))
  val username = sys.props("user.name")
  import fansi.Color._
  repl.prompt.bind("" + DarkGray("[") + LightBlue(username) + DarkGray("@") + LightMagenta(hostname) + DarkGray("] ") + LightGray(wd match { case Home => "~"; case `root` => "/"; case other => other.baseName }) + DarkGray(" $") + Reset(" "))
and Console.println(repl.prompt() shows the correct colors, but the actual prompt is reset to white
Li Haoyi
Can you replace fansi.Colors.Reset with fansi.Attrs.Empty
I think the interp.colors.prompt is being applied on top of the repl.prompt and resetting all your colors
Thomas Dickerson
that appears to work =)