Skip to content

Commit

Permalink
Allow customizing the kernel display name
Browse files Browse the repository at this point in the history
This adds a `installkernel(; displayname)` argument to let the user specify the
kernel display name completely.
  • Loading branch information
JamesWrigley committed Dec 16, 2024
1 parent 7d1030e commit b93499c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
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

0 comments on commit b93499c

Please sign in to comment.