Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 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

    (compare)

  • 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
James Kyle
@jameskyle

Hey, everyone. In my environment I'm getting a method not found error from protobuf: java.lang.NoSuchMethodError: com.google.protobuf.descriptor.FileDescriptorProto$.parseFrom(. When I checked the location of the class, it's being loaded from the amm binary. I think it's due to a conflict between an older protobuf library bundled with ammonite and the protobuf that my runtime libraries are depending on.

@ import  com.google.protobuf.descriptor.FileDescriptorProto
import  com.google.protobuf.descriptor.FileDescriptorProto

@ val klass = classOf[FileDescriptorProto]
klass: Class[FileDescriptorProto] = class com.google.protobuf.descriptor.FileDescriptorProto

@ klass.getResource('/' + klass.getName().replace('.', '/') + ".class")
res5: java.net.URL = jar:file:/usr/local/bin/amm!/com/google/protobuf/descriptor/FileDescriptorProto.class

I think this issue might be related (com-lihaoyi/Ammonite#1177), however when I try the suggested --thin flag I get errors for missing sun.reflect dependencies java.lang.NoClassDefFoundError: sun/reflect/ConstructorAccessorImpl

James Kyle
@jameskyle
ping
Paul Bryan
@locke8
Hi all, can anyone tell me if Ammonite supports development of Scala 3?
I ask because this code: "opaque type Command = String", gives me an error [; expected but type found] if I run as Ammonite script but works within a worksheet. I'm using latest version of Metals.
Stefano Sgorlon
@gokyo
I'd like to import some extra .class files (located in an external folder) using interp.load.cp or $cp. Do you have a working example?
Tobias Roeser
@lefou
import $cp.external
eric-bzb
@eric-bzb
is there an ammonite equivalent to mill -i ... ? For example, I've noticed that I need to pass -i to mill -i main.run in order for a (cats-effect) readLine to actually work. Without the -i it just hangs when it gets to readLine. I'm wondering if anyone has had the same issue with ammonite?
Tobias Roeser
@lefou
@eric-bzb That's because mill uses a client-server-setup to speed up repetitiv build tasks. This should not needed in ammonite, as ammonite runs in a single process and has therefore access to the system input. It should be always interactive.
eric-bzb
@eric-bzb

@lefou ok, thanks. It is odd then that Ammonite seems to have trouble running things like amm Example.sc where Example.sc contains:

//Example.sc
import $ivy.`org.typelevel::cats-effect:3.2.5`
import cats.effect.unsafe.implicits._ 
import cats.effect.IO 
val run = for {
  _ <- IO.println("Hello")
  _ <- IO.println("World")
  input <- IO.readLine
  _ <- IO.println(s"echo $input")
} yield ()
run.unsafeRunSync()

For me, it only prints "Hello" and then hangs.

and the oddity is that pasting the above directly into an already-running ammonite repl seems to instead work just fine... it's the command amm Example.sc that does not seem to work properly
Jesse Atkinson
@jsatk
I upgraded my repo to 2.12.14 but now I'm getting this error on compile. Any ideas? [error] Error downloading com.lihaoyi:ammonite-interp_2.12.14:1.8.2
Chris Kipp
@ckipp:matrix.org
[m]
that artifact doesn't exist @jsatk
it looks like for 2.12.14 the only version of ammonite-interp that are available are a bunch of snapshots
you can see this with
cs complete com.lihaoyi:ammonite-interp_2.12.14:
Jesse Atkinson
@jsatk
Ah. Thanks. I thought so but i was like "that can't be right".
So as it stands... if I want to upgrade from 2.12.12 to 2.12.14 I can't because Bloop plugin is required for Metals? I'd have to use intelliJ? :(
the bloop plugin is what I believes attempts to pull down ammonite.
when i compile
Chris Kipp
@ckipp:matrix.org
[m]
I don't think that should be the issues. Lots of Metals users use 2.12.14, so if that was the case would would have hit on that.
you should be able to use something like sbt whatDependsOn or even coursier resolve to see what is actually pulling that in
daravep
@daravep

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)
        at

Is this not supported?

1 reply
discobaba
@uncleweirdo_twitter
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
@arteme
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
@arteme
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
@fizzy33
is there a way to have a ammonite script define a function. So ideally I would like a file with something like...
myplugin.scala
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 {
 ...
}

context.registerPlugin(myplugin)
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.
Jonathan
@mksrew_gitlab

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

object BuildingBlocks extends Plugin {
   ...
}
val plugin = BuildingBlocks

Then load it like:

import $file.MyPlugin

println(MyPlugin.plugin)
Glen Marchesani
@fizzy33
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
@fizzy33
to be clear this is a scala app
Li Haoyi
@lihaoyi
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
@faustas
Hi, one question. Is there a possibility to check unused imports or execute code formatting for ammonite scripts?
Glen Marchesani
@fizzy33
thanks @lihaoyi
any chance you can point at mill code that does that ?
Li Haoyi
@lihaoyi
@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
emeinhardt
@emeinhardt
@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
@mkneissl
Hi, I'm starting with ammonite (again) and keep getting missing implicit pretty printers.
$ amm
Loading...
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
eric-bzb
@eric-bzb
@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
@fizzy33
thanks @lihaoyi I can bootstrap a lot from that :-)
Mahdi Robatipoor
@robatipoor
How i can run ammonite on scala 3 ?
Glen Marchesani
@fizzy33

@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 =
    ammonite.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) ^