Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for Kotlin kernel #5590

Merged
merged 14 commits into from Jul 5, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
78 changes: 78 additions & 0 deletions demoFiles/Kotlin-example.ipynb
@@ -0,0 +1,78 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Hello, world! 66666\n"
]
},
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 1,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"println(\"Hello, world! 66666\")"
]
},
{
"cell_type": "code",
"execution_count": 3,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"null"
]
},
"execution_count": 3,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"val plot = Plot()\n",
"plot.display()"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": true
},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Kotlin",
"language": "kotlin",
"name": "kotlin"
},
"language_info": {
"codemirror_mode": "groovy",
"file_extension": ".groovy",
"mimetype": "",
"name": "Groovy",
"nbconverter_exporter": "",
"version": "unkown"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
3 changes: 3 additions & 0 deletions kernel/kotlin/.gitignore
@@ -0,0 +1,3 @@
/bin/
/.classpath
/.project
105 changes: 105 additions & 0 deletions kernel/kotlin/build.gradle
@@ -0,0 +1,105 @@
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
apply plugin: 'application'
apply plugin: 'java'
apply plugin: 'maven-publish'

def final kernelIdName = 'kotlin'
def final toReplace = '__PATH__'

mainClassName = 'com.twosigma.beakerx.kotlin.kernel.Kotlin'

repositories {
mavenCentral()
}

dependencies {
compile project(':kernel:base')
compile group: 'org.jetbrains.kotlin', name: 'kotlin-compiler', version: '1.1.3'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-script-runtime', version: '1.1.3'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-runtime', version: '1.1.3'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-reflect', version: '1.1.3'

}

jar {
manifest {
attributes "Main-Class": "$mainClassName"
}

from {
configurations.compile.collect { it.isDirectory() ? it : zipTree(it) }
} {
exclude "META-INF/*.SF"
exclude "META-INF/*.DSA"
exclude "META-INF/*.RSA"
}
}

task prepareJson(dependsOn: 'build') {
doLast {
println "Prepare JSON for Jupyter notebook"
println "Copy kernel.json to build/libs/json/ and replacing PATH with kotlin.jar path"

def jarLocation = file('build/libs/kotlin.jar').getAbsolutePath()
jarLocation = jarLocation.replace("\\", "/");
def text = file('kernel.json').text.replace(toReplace, jarLocation)
def folder = file('build/libs/json')
if (!folder.exists()) {
println "Creating folder build/libs/json"
folder.mkdirs()
}

file('build/libs/json/kernel.json').withWriter { w ->
w << text
}
}
}

task kernelInstall(dependsOn: 'prepareJson') {
doLast {
println "Installing 'kotlin' to jupyter notebook"

def hashStdOut = new ByteArrayOutputStream()
def jsonFolder = file('build/libs/json/').getAbsolutePath();
exec {
commandLine "jupyter",
"kernelspec",
"install",
"--sys-prefix",
"--replace",
"--name",
kernelIdName,
jsonFolder;
standardOutput = hashStdOut
}
println hashStdOut.toString().trim();
println "DONE"
}
}


publishing {
publications {
maven(MavenPublication) {
groupId 'com.twosigma'
artifactId 'beaker-kernel-kotlin'
version '2.0-SNAPSHOT'

from components.java
}
}
}
6 changes: 6 additions & 0 deletions kernel/kotlin/kernel.json
@@ -0,0 +1,6 @@
{
"argv": [ "java", "-jar", "__PATH__", "{connection_file}" ],
"display_name": "Kotlin",
"language": "kotlin",
"env": { "PS1":"kotlin>"}
}
6 changes: 6 additions & 0 deletions kernel/kotlin/kernel_debug.json
@@ -0,0 +1,6 @@
{
"argv": [ "java", "-jar", "-Xdebug", "-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=9090", "__PATH__", "{connection_file}" ],
"display_name": "Kotlin",
"language": "kotlin",
"env": { "PS1":"kotlin>"}
}
@@ -0,0 +1,44 @@
/*
* Copyright 2017 TWO SIGMA OPEN SOURCE, LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.twosigma.beakerx.kotlin.comm;

import com.twosigma.beakerx.kernel.KernelFunctionality;
import com.twosigma.beakerx.handler.Handler;
import com.twosigma.beakerx.message.Message;
import com.twosigma.beakerx.kernel.comm.KernelControlCommandListHandler;
import com.twosigma.beakerx.kernel.comm.KernelControlInterrupt;
import com.twosigma.beakerx.kernel.comm.TargetNamesEnum;
import com.twosigma.beakerx.kernel.handler.CommOpenHandler;

public class KotlinCommOpenHandler extends CommOpenHandler{

private Handler<?>[] KERNEL_CONTROL_CHANNEL_HANDLERS = {
new KernelControlInterrupt(kernel),
new KernelControlCommandListHandler(kernel)};

public KotlinCommOpenHandler(KernelFunctionality kernel) {
super(kernel);
}

public Handler<Message>[] getKernelControlChanelHandlers(String targetName){
if(TargetNamesEnum.KERNEL_CONTROL_CHANNEL.getTargetName().equalsIgnoreCase(targetName)){
return (Handler<Message>[]) KERNEL_CONTROL_CHANNEL_HANDLERS;
}else{
return (Handler<Message>[]) new Handler<?>[0];
}
}

}