Skip to content

Commit 1e416c7

Browse files
authored
Library configuration improvements (#34)
* Split library descriptors into separate jsons * Load local library descriptors from "/.jupyter_kotlin/libraries" directory * Asynchronously download library descriptors from master branch of "https://github.com/Kotlin/kotlin-jupyter" repository * Cache downloaded descriptors in "/.jupyter_kotlin/cache/libraries" directory * Check library descriptor format version and suggest updating kernel if format was changed
1 parent b9dadc8 commit 1e416c7

File tree

23 files changed

+620
-328
lines changed

23 files changed

+620
-328
lines changed

build.gradle

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@ allprojects {
4444
project.getProperty('installPath') :
4545
Paths.get(System.properties['user.home'].toString(), ".ipython", "kernels", "kotlin").toAbsolutePath().toString()
4646
ext.debugPort = 1044
47-
ext.configFile = "config.json"
4847
ext.debuggerConfig = "-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=$debugPort"
4948
}
5049

@@ -69,6 +68,7 @@ dependencies {
6968

7069
compile "org.apache.maven:maven-core:3.0.3"
7170
compile 'org.slf4j:slf4j-api:1.7.25'
71+
compile "khttp:khttp:1.0.0"
7272
compile 'org.zeromq:jeromq:0.3.5'
7373
compile 'com.beust:klaxon:5.2'
7474
runtime 'org.slf4j:slf4j-simple:1.7.25'
@@ -117,7 +117,7 @@ void createTaskForSpecs(Boolean debug) {
117117
} .join(File.pathSeparator)
118118
spec = substitute(spec, "RUNTIME_CLASSPATH", libsCp)
119119
spec = substitute(spec, "DEBUGGER_CONFIG", debug ? "\"$debuggerConfig\"," : "")
120-
spec = substitute(spec, "LIBRARIES_PATH", "$installPath$sep$configFile")
120+
spec = substitute(spec, "KERNEL_HOME", "$installPath")
121121
File installDir = new File("$installPath")
122122
if (!installDir.exists()) {
123123
installDir.mkdirs();
@@ -138,9 +138,9 @@ static String substitute(String spec, String template, String val) {
138138
return spec.replace("\${$template}", val.replace("\\", "\\\\"))
139139
}
140140

141-
task copyLibrariesConfig(type: Copy, dependsOn: cleanInstallDir) {
142-
from configFile
143-
into installPath
141+
task copyLibraries(type: Copy, dependsOn: cleanInstallDir) {
142+
from "libraries"
143+
into Paths.get(installPath, "libraries").toString()
144144
}
145145

146146
createTaskForSpecs(true)
@@ -151,8 +151,8 @@ task installLibs(type: Copy, dependsOn: cleanInstallDir) {
151151
from configurations.deploy
152152
}
153153

154-
task install(dependsOn: [installKernel, installLibs, createSpecs, copyLibrariesConfig]) {
154+
task install(dependsOn: [installKernel, installLibs, createSpecs, copyLibraries]) {
155155
}
156156

157-
task installDebug(dependsOn: [installKernel, installLibs, createDebugSpecs, copyLibrariesConfig]) {
157+
task installDebug(dependsOn: [installKernel, installLibs, createDebugSpecs, copyLibraries]) {
158158
}

config.json

Lines changed: 0 additions & 184 deletions
This file was deleted.

kernelspec/kernel.json.template

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"argv": [ "java", "-jar", ${DEBUGGER_CONFIG} "${KERNEL_JAR_PATH}", "{connection_file}", "-cp=${RUNTIME_CLASSPATH}", "-libs=${LIBRARIES_PATH}"],
2+
"argv": [ "java", "-jar", ${DEBUGGER_CONFIG} "${KERNEL_JAR_PATH}", "{connection_file}", "-cp=${RUNTIME_CLASSPATH}", "-home=${KERNEL_HOME}"],
33
"display_name": "Kotlin",
44
"language": "kotlin"
55
}

libraries/.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
formatVersion=1

libraries/gral.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"properties": {
3+
"v": "0.11"
4+
},
5+
"link": "https://github.com/eseifert/gral",
6+
"dependencies": [
7+
"de.erichseifert.gral:gral-core:$v"
8+
],
9+
"imports": [
10+
"de.erichseifert.gral.data.*",
11+
"de.erichseifert.gral.data.filters.*",
12+
"de.erichseifert.gral.graphics.*",
13+
"de.erichseifert.gral.plots.*",
14+
"de.erichseifert.gral.plots.lines.*",
15+
"de.erichseifert.gral.plots.points.*",
16+
"de.erichseifert.gral.util.*"
17+
],
18+
"init": [
19+
"fun<T: Drawable> T.show(sizeX: Double, sizeY: Double): Any {\n val writer = de.erichseifert.gral.io.plots.DrawableWriterFactory.getInstance().get(\"image/svg+xml\")\n\n val buf = java.io.ByteArrayOutputStream()\n\n writer.write(this, buf, sizeX, sizeY)\n\n return MIME(writer.mimeType to buf.toString())\n}"
20+
]
21+
}

libraries/klaxon.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"properties": {
3+
"v": "5.2"
4+
},
5+
"link": "https://github.com/cbeust/klaxon",
6+
"dependencies": [
7+
"com.beust:klaxon:$v"
8+
],
9+
"imports": [
10+
"com.beust.klaxon.*"
11+
]
12+
}

libraries/kmath.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"properties": {
3+
"v": "0.1.3"
4+
},
5+
"link": "https://github.com/mipt-npm/kmath",
6+
"repositories": [
7+
"https://dl.bintray.com/mipt-npm/scientifik"
8+
],
9+
"dependencies": [
10+
"scientifik:kmath-core-jvm:$v"
11+
],
12+
"imports": [
13+
"scientifik.kmath.linear.*",
14+
"scientifik.kmath.operations.*",
15+
"scientifik.kmath.structures.*"
16+
]
17+
}

libraries/koma.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
{
2+
"properties": {
3+
"v": "0.13"
4+
},
5+
"link": "https://koma.kyonifer.com/index.html",
6+
"repositories": [
7+
"https://dl.bintray.com/kyonifer/maven"
8+
],
9+
"dependencies": [
10+
"com.kyonifer:koma-core-ejml:$v",
11+
"com.kyonifer:koma-plotting:$v"
12+
],
13+
"imports": [
14+
"koma.*",
15+
"koma.extensions.*"
16+
]
17+
}

libraries/kotlin-statistics.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{
2+
"properties": {
3+
"v": "-SNAPSHOT"
4+
},
5+
"link": "https://github.com/thomasnield/kotlin-statistics",
6+
"dependencies": [
7+
"com.github.thomasnield:kotlin-statistics:$v"
8+
],
9+
"imports": [
10+
"org.nield.kotlinstatistics.*"
11+
]
12+
}

libraries/krangl.json

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
{
2+
"properties": {
3+
"v": "-SNAPSHOT"
4+
},
5+
"link": "https://github.com/holgerbrandl/krangl",
6+
"dependencies": [
7+
"com.github.holgerbrandl:krangl:$v"
8+
],
9+
"imports": [
10+
"krangl.*"
11+
],
12+
"init": [
13+
"fun krangl.DataFrame.toHTML(limit: Int = 20, truncate: Int = 50) : String\n{val sb = StringBuilder()\nsb.append(\"<html><body>\")\nsb.append(\"<table><tr>\")\ncols.forEach { sb.append(\"<th style=\\\"text-align:left\\\">${it.name}</th>\") }\nsb.append(\"</tr>\")\nrows.take(limit).forEach {\n sb.append(\"<tr>\")\n it.values.map{it.toString()}.forEach { \n val truncated = if (truncate > 0 && it.length > truncate) {\n if (truncate < 4) it.substring(0, truncate)\n else it.substring(0, truncate - 3) + \"...\"\n } else {\n it\n }\n sb.append(\"\"\"<td style=\"text-align:left\" title=\"$it\">$truncated</td>\"\"\") \n }\n sb.append(\"</tr>\")\n}\nsb.append(\"</table>\")\nif(limit < rows.count())\n sb.append(\"<p>... only showing top $limit rows</p>\")\nsb.append(\"</body></html>\")\nreturn sb.toString()}"
14+
],
15+
"renderers": [
16+
{
17+
"class": "krangl.SimpleDataFrame",
18+
"result": "HTML($it.toHTML())"
19+
}
20+
]
21+
}

0 commit comments

Comments
 (0)