twosigma / beakerx

Beaker Extensions for Jupyter Notebook
http://BeakerX.com
Apache License 2.0
2.8k stars 382 forks source link

Annotation driven dependency declaration for Kotlin kernel #6981

Open holgerbrandl opened 6 years ago

holgerbrandl commented 6 years ago

Using magic commands are common in a jupyter context, but illicit according to kotlin (and I guess java) language spec. So exporting e.g. kts scripts from a notebook, could strip all magics, which will loose all dependencies declarations. Or it could keep them, but the result would be non-compilable.

An annotation-driven configuration would be beneficial, because it's compatible with the kotlin language specs.

// To use a custom maven repository you can declare it with
@file:MavenRepository("imagej-releases","http://maven.imagej.net/content/repositories/releases" )

@file:DependsOnMaven("net.clearvolume:cleargl:2.0.1")

For example details see https://github.com/holgerbrandl/kscript#annotation-driven-script-configuration

Such an approach is implemented in the other kotlin kernel https://github.com/ligee/kotlin-jupyter and for scripting in https://github.com/holgerbrandl/kscript

Clearly, having different annotations to declare dependencies across different types of scripting tooling won't give any benefits to the user, but there's a KEEP https://github.com/Kotlin/KEEP/issues/75 trying to unify these annotations. Maybe beakerx could implement the proposal once it's ready? (fyi @ligee)

scottdraves commented 6 years ago

Thank you for your suggestion, Holger. I don't know much about Kotlin, so your feedback is especially useful. Please forgive me however if some extra explanation is required for me understand it, however.

If Kotlin standardizes a scripting version then I would be happy to use it. Currently we are using the embeddable compiler (https://github.com/twosigma/beakerx/blob/56653e6012a97914a7ad88416e610b0df06fb6ec/kernel/kotlin/build.gradle#L43) but it doesn't have APIs for things like autocomplete, so it's not ideal.

However I am not sure I understand the annotation system and how it relates to the magics. If the Kotlin script system implements these annotations then wouldn't they "just work" in BeakerX, similar to how Groovy's Grape works (http://nbviewer.jupyter.org/github/twosigma/beakerx/blob/master/doc/groovy/ClasspathMagicCommands.ipynb)?

holgerbrandl commented 6 years ago

You would not use any magics but simply evaluate a code cell that contains an special annotation that is declaring a dependency. Indeed the @Grab looks very similar here.

And it could work the same way with java I guess.

I have no opinion nor experience with the compiler internals, but I guess the Kotlin Slack forum is a good place to ask. Or @ligee might now?

Stvad commented 6 years ago

What is the current suggested way of handling dependencies? I can't seem to find a documentation about it =\ I see %import in the cheatsheet, but how do I point it to jar/repository/etc?

Stvad commented 6 years ago

Ah, there is %classpath as well