Kotlin / kotlin-jupyter

Kotlin kernel for Jupyter/IPython
Apache License 2.0
1.11k stars 107 forks source link

Make platform available to LibraryDefinitionProducer #283

Closed rnett closed 3 years ago

rnett commented 3 years ago

I'm looking at adding integration for tensorflow. There is a large native dependency, and while I can just depend on the all-platforms bundle, I would like to depend on only the current platform's (or error if it's not supported). Presumably the way to do this would be via a LibraryDefinitionProducer, but as far as I can see there is no way to get the platform. Will there be issues if I use the current JVM's methods (i.e. System.getProperty("os.name") in my LibraryDefinitionProducer)?

ileasile commented 3 years ago

There should be no issues. You may use system properties in your integration class and add dependencies/imports/whatever based on them

rnett commented 3 years ago

Nice. Two further questions:

  1. Is there a way to depend on another library w/ the same version as the current integration? Or to access the asked for version in my integration?
  2. Are there any repositories included by default? I'm looking at integrations like serialization's that don't declare any.
ileasile commented 3 years ago

Sorry for delay, I have been vacationing 🌴

  1. You may use %use magic in your library init code. For JSON descriptor: { "init": ["%use someOtherLib"] } For new-way integration:
    onLoaded {
    execute("%use someOtherLib")
    }
  2. Repositories included by default are listed here: https://github.com/Kotlin/kotlin-jupyter/blob/0dc5720df110f51e8c505d67e05d5f9d2d2cd5d9/jupyter-lib/shared-compiler/src/main/kotlin/org/jetbrains/kotlinx/jupyter/config/defaultImports.kt#L8 They are Central and JitPack currently.
rnett commented 3 years ago

No worries, this isn't urgent. I should clarify 1: I'm trying to depend on another module in the same project, so for example if you use @DependsOn("my.lib:a:0.2.0" I want to depend on my.lib:b:0.2.0. If I understand the %use magics right, they would use the configured version from the kernel (which is generally the latest), which wouldn't work if the user was depending on an old version initially.

After looking through the code, it does not seem easily possible.

ileasile commented 3 years ago

What I'd do in your case.

  1. In buildscript of module :a: implementation(":b")
  2. Setup publication in both :a and :b
  3. Publish 0.2.0 version of these packages to some repository (mavenLocal or remote)
  4. @DependsOn("my.lib:a:0.2.0") in notebook should work as you expect

If it is not applicable, please clarify a bit more)

rnett commented 3 years ago

Yeah, unfortunately this is combined with the artifact depending on the OS, so it's more like I need to depend on my.lib:b:jar:$os:0.2.0. I think adding a resource file with the current version is as good as I'm going to be able to get, which works well enough.

For reference this is what I'm doing currently.

ileasile commented 3 years ago

Yes, resource file with the version should be the way

ileasile commented 3 years ago

I'm closing this issue because solution exists and it's hard to invent something better