alexarchambault on 1.6.3
alexarchambault on master
1.6.3 (compare)
lihaoyi on gh-pages
5ad9ae5538f23cab92ccd8c6b1617d8… (compare)
alexarchambault on master
Partly revert 84d48542 (#923) … (compare)
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?
object myplugin extends Plugin {
...
}
context.registerPlugin(myplugin)
@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)
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.
@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.
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)""")
cmd0.sc:1: not found: value Bob
val res = println(Bob.toString)
^
results
I can see there is a "Bob" term in the script but how do I get to access it's actual instance
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.
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.
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-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
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(" "))
}