Skip to content

Commit

Permalink
Merge pull request #210 from Carreau/kernelspec
Browse files Browse the repository at this point in the history
add kernelspec for IPython 3.0
  • Loading branch information
stevengj committed Feb 20, 2015
2 parents 1015671 + 8442a03 commit 6981f1b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 9 deletions.
1 change: 1 addition & 0 deletions .gitignore
@@ -1,2 +1,3 @@
*.pyc
*.un~
/build/
62 changes: 53 additions & 9 deletions deps/build.jl
@@ -1,6 +1,8 @@
# TODO: Build IPython 1.0 dependency? (wait for release?)
# TODO: Buld IPython 1.0 dependency? (wait for release?)

#######################################################################
import JSON
using Compat

# print to stderr, since that is where Pkg prints its messages
eprintln(x...) = println(STDERR, x...)
Expand All @@ -25,7 +27,7 @@ juliaprof = chomp(readall(`$ipython locate profile julia`))

# set c.$s in prof file to val, or nothing if it is already set
# unless overwrite is true
function add_config(prof::String, s::String, val, overwrite=false)
function add_config(prof::String, s::String, val; overwrite::Bool=false)
p = joinpath(juliaprof, prof)
r = Regex(string("^[ \\t]*c\\.", replace(s, r"\.", "\\."), "\\s*=.*\$"), "m")
if isfile(p)
Expand Down Expand Up @@ -65,15 +67,26 @@ end

# add Julia kernel manager if we don't have one yet
if VERSION >= v"0.3-"
binary_name = "julia"
binary_name = @windows? "julia.exe":"julia"
else
binary_name = "julia-basic"
binary_name = @windows? "julia.bat":"julia-basic"
end

kernelcmd_array = [escape_string(joinpath(JULIA_HOME,("$binary_name")))]

if VERSION >= v"0.3"
push!(kernelcmd_array,"-i")
end

append!(kernelcmd_array, ["-F", escape_string(joinpath(Pkg.dir("IJulia"),"src","kernel.jl")), "{connection_file}"])



kernelcmd = JSON.json(kernelcmd_array)

add_config("ipython_config.py", "KernelManager.kernel_cmd",
VERSION >= v"0.3"?
"""["$(escape_string(joinpath(JULIA_HOME,(@windows? "julia.exe":"$binary_name"))))", "-i", "-F", "$(escape_string(joinpath(Pkg.dir("IJulia"),"src","kernel.jl")))", "{connection_file}"]""":
"""["$(escape_string(joinpath(JULIA_HOME,(@windows? "julia.bat":"$binary_name"))))", "-F", "$(escape_string(joinpath(Pkg.dir("IJulia"),"src","kernel.jl")))", "{connection_file}"]""",
true)
kernelcmd,
overwrite=true)

# make qtconsole require shift-enter to complete input
add_config("ipython_qtconsole_config.py",
Expand All @@ -96,7 +109,7 @@ eqb(a::Vector{Uint8}, b::Vector{Uint8}) =
# copy IJulia/deps/src to destpath/destname if it doesn't
# already exist at the destination, or if it has changed (if overwrite=true).
function copy_config(src::String, destpath::String,
destname::String=src, overwrite=true)
destname::String=src; overwrite::Bool=true)
mkpath(destpath)
dest = joinpath(destpath, destname)
srcbytes = rb(joinpath(Pkg.dir("IJulia"), "deps", src))
Expand All @@ -122,9 +135,16 @@ copy_config("ijuliafavicon.ico",
joinpath(juliaprof, "static", "base", "images"),
"favicon.ico")

# On IPython < 3.
# custom.js can contain custom js login that will be loaded
# with the notebook to add info and/or monkey-patch some javascript
# -- e.g. we use it to add .ipynb metadata that this is a Julia notebook

# on IPython 3+, still upgrade custom.js because old version can prevent
# notebook from loading.
# todo: maybe do not copy if don't exist.
# todo: maybe remove if user custom.js is identical to the one
# shiped with IJulia ?
copy_config("custom.js", joinpath(juliaprof, "static", "custom"))

# julia.js implements a CodeMirror mode for Julia syntax highlighting in the notebook.
Expand All @@ -133,3 +153,27 @@ copy_config("custom.js", joinpath(juliaprof, "static", "custom"))
copy_config("julia.js", joinpath(juliaprof, "static", "components", "codemirror", "mode", "julia"))

#######################################################################
# Part specific to Jupyter/IPython 3.0 and above
#######################################################################


juliakspec = joinpath(chomp(readall(`$ipython locate`)),"kernels","julia")
ks = @compat Dict(
"argv" => kernelcmd_array,
"display_name" => "Julia "*string(VERSION),
"language" => "julia",
)

destname = "kernel.json"
mkpath(juliakspec)
dest = joinpath(juliakspec, destname)


eprintln("Writing IJulia kernelspec to $dest ...")

open(dest, "w") do f
# indent by 2 for readability of file
write(f, JSON.json(ks, 2))
end
copy_config("logo-32x32.png", juliakspec)
copy_config("logo-64x64.png", juliakspec)
Binary file added deps/logo-32x32.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added deps/logo-64x64.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6981f1b

Please sign in to comment.