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

Allow customizing the kernel display name #1137

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 11 additions & 1 deletion deps/kspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,16 @@ else
exe(s::AbstractString, e::AbstractString) = s * e
end

function display_name(name::AbstractString)
debugdesc = ccall(:jl_is_debugbuild,Cint,())==1 ? "-debug" : ""
return name * " " * Base.VERSION_STRING * debugdesc
end

"""
installkernel(name::AbstractString, options::AbstractString...;
julia::Cmd,
specname::AbstractString,
displayname::AbstractString,
env=Dict())

Install a new Julia kernel, where the given `options` are passed to the `julia`
Expand All @@ -71,6 +77,9 @@ kernelpath = installkernel("Julia O3", "-O3", env=Dict("FOO"=>"yes"))
creates a new Julia kernel in which `julia` is launched with the `-O3`
optimization flag and `FOO=yes` is included in the environment variables.

The `displayname` argument can be used to customize the name displayed in the
Jupyter kernel list.

The returned `kernelpath` is the path of the installed kernel directory,
something like `/...somepath.../kernels/julia-o3-1.6` (in Julia 1.6). The
`specname` argument can be passed to alter the name of this directory (which
Expand All @@ -96,6 +105,7 @@ installkernel(
function installkernel(name::AbstractString, julia_options::AbstractString...;
julia::Cmd = `$(joinpath(Sys.BINDIR,exe("julia")))`,
specname::AbstractString = kernelspec_name(name),
displayname::AbstractString = display_name(name),
env::Dict{<:AbstractString}=Dict{String,Any}())
# Is IJulia being built from a debug build? If so, add "debug" to the description.
debugdesc = ccall(:jl_is_debugbuild,Cint,())==1 ? "-debug" : ""
Expand All @@ -112,7 +122,7 @@ function installkernel(name::AbstractString, julia_options::AbstractString...;

ks = Dict(
"argv" => kernelcmd_array,
"display_name" => name * " " * Base.VERSION_STRING * debugdesc,
"display_name" => displayname,
"language" => "julia",
"env" => env,
# Jupyter's signal interrupt mode is not supported on Windows
Expand Down
6 changes: 5 additions & 1 deletion test/install.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@ import IJulia, JSON
end
end

let kspec = IJulia.installkernel("ahzAHZ019.-_ ~!@#%^&*()")
let kspec = IJulia.installkernel("ahzAHZ019.-_ ~!@#%^&*()"; displayname="foo")
try
@test occursin("ahzahz019.-_-__________", basename(kspec))

let k = open(JSON.parse, joinpath(kspec, "kernel.json"))
@test k["display_name"] == "foo"
end
finally
rm(kspec, force=true, recursive=true)
end
Expand Down
Loading