jove.JupyterModule.scala Maven / Gradle / Ivy
The newest version!
package jove
import java.io.File
import com.typesafe.config.ConfigFactory
import scala.sys.process._
import scala.util.{Success, Failure, Try}
object JupyterModule extends Module {
private val configPythonPath = "jove.modules.jupyter.pythonPath"
private val anacondaDirs = List("anaconda3", "miniconda3", "anaconda", "miniconda")
private def defaultPythonPath =
anacondaDirs.map(d => (new File(sys.props.get("user.home").getOrElse(".")) /: List(d, "bin", "python"))(new File(_, _)))
.find(_.isFile).map(_.getAbsolutePath)
def kernels: Map[String, (Kernel, KernelInfo)] = {
val kernelConfig = ConfigFactory load "jove"
var m = Map.empty[String, (Kernel, KernelInfo)]
/* IPython kernel */
val pythonPath = {
val opt =
if (kernelConfig hasPath configPythonPath)
Some(kernelConfig getString configPythonPath).filter(_.nonEmpty)
else
defaultPythonPath
opt getOrElse "python"
}
Try(List(pythonPath, "--version").!!(ProcessLogger(_ => (), _ => ()))) match {
case Success(output) =>
m += "ipython" -> (PythonZMQKernel(pythonPath), KernelInfo("Python", List("ipynb")))
case Failure(err) =>
}
/* IHaskell */
val ihaskellPath =
Some((new File(sys.props.get("user.home").getOrElse(".")) /: List(".cabal", "bin", "IHaskell"))(new File(_, _)))
.filter(_.isFile).map(_.getAbsolutePath).getOrElse("IHaskell")
Try(List(ihaskellPath, "--help").!!(ProcessLogger(_ => (), _ => ()))) match {
case Success(output) =>
m += "haskell" -> (IHaskellZMQKernel(ihaskellPath), KernelInfo("IHaskell", List("hnb")))
case Failure(err) =>
}
m
}
}