-
Notifications
You must be signed in to change notification settings - Fork 241
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ec47c3b
commit 26c995a
Showing
10 changed files
with
116 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
modules/scala/toree-hooks/src/main/scala/almond/toree/ToreeCompatibility.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package almond.toree | ||
|
||
import almond.interpreter.api.DisplayData | ||
import ammonite.interp.api.InterpAPI | ||
|
||
import java.io.{InputStream, PrintStream} | ||
import java.net.URI | ||
import java.nio.file.Paths | ||
|
||
/** Import the members of this object to add source-compatibility for some Toree API calls, such as | ||
* 'kernel.display', or 'kernel.addJars'. | ||
*/ | ||
object ToreeCompatibility { | ||
implicit class KernelToreeOps(private val kernel: almond.api.JupyterApi) { | ||
|
||
def display: ToreeDisplayMethodsLike = | ||
new ToreeDisplayMethodsLike { | ||
def content(mimeType: String, data: String) = | ||
kernel.publish.display(DisplayData(Map(mimeType -> data))) | ||
def clear(wait: Boolean = false) = | ||
// no-op, not sure what we're supposed to do here… | ||
() | ||
} | ||
|
||
def out: PrintStream = System.out | ||
def err: PrintStream = System.err | ||
def in: InputStream = System.in | ||
|
||
def addJars(uris: URI*)(implicit interp: InterpAPI): Unit = { | ||
val (fileUris, other) = uris.partition(_.getScheme == "file") | ||
for (uri <- other) | ||
System.err.println(s"Warning: ignoring $uri") | ||
val files = fileUris.map(Paths.get(_)).map(os.Path(_, os.pwd)) | ||
interp.load.cp(files) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
modules/scala/toree-hooks/src/main/scala/almond/toree/ToreeDisplayMethodsLike.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package almond.toree | ||
|
||
trait ToreeDisplayMethodsLike { | ||
def content(mimeType: String, data: String): Unit | ||
def html(data: String): Unit = content("text/html", data) | ||
def javascript(data: String): Unit = content("application/javascript", data) | ||
def clear(wait: Boolean = false): Unit | ||
} |