Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.09k stars 106 forks source link

question: how to import code from an external module #390

Open AngryMaciek opened 1 year ago

AngryMaciek commented 1 year ago

Im a rather newbie in Kotlin but I was wondering if there is a mechanism to import classes, functions I have in an external text file (not in the same directory)? Would be a very useful feature as defining hundreds of code lines in a notebook impairs brevity, better to put them out in a separate file and just "load" in the nb, right?

ileasile commented 1 year ago

Hi! It's only possible to import compiled modules and classes for now. In Kotlin Notebook intellij plugin you can access the source code of the project too

AngryMaciek commented 1 year ago

This issue is not really addressed, I don't understand why is this being closed.

  1. Could you please provide me with an example or a documentation link to how to include a compiled module?
  2. Does this kernel support %%bash magic cells to call compilation of an external module; that one which I would later like to load? If not - how do I achieve this?
ileasile commented 1 year ago

Sorry, I didn't notice your question...

  1. Sure: https://github.com/Kotlin/kotlin-jupyter#dependencies-resolving-annotations
  2. We have proprocessors, one of our users solved very similar problem here: https://github.com/Kotlin/kotlin-jupyter/issues/223#issuecomment-840521470
KubaOfca commented 1 year ago

Is there a way to install kotlin compiler in conda environment? I want to compile the script by run (inside conda env with kotlin-jupyter installed):

kotlinc -script custom.kts -include-runtime -d example.jar

but i got a message that

Command 'kotlinc' not found
ileasile commented 1 year ago

Why don't you want to simply use kotlin command-line compiler? https://kotlinlang.org/docs/command-line.html#install-the-compiler

kotlin-jupyter is a Kotlin kernel for jupyter, it doesn't separately install the compiler

AngryMaciek commented 1 year ago

Thanks for the link! I can download the compiler manually, indeed. I think that solves it :)