Skip to content

Commit

Permalink
0.7 compatibility (mostly)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Apr 19, 2018
1 parent 5715e95 commit 137fcf7
Show file tree
Hide file tree
Showing 19 changed files with 99 additions and 101 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ os:
julia:
- 0.6
- nightly
matrix:
allow_failures:
- julia: nightly
notifications:
email: false
script:
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ julia 0.6
MbedTLS 0.4.3
JSON 0.5
ZMQ 0.6.0
Compat 0.41.0
Compat 0.47.0
Conda 0.1.5
10 changes: 5 additions & 5 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function prog_version(prog)
return nothing
end
try
return convert(VersionNumber, v)
return VersionNumber(v)
catch
warn("`$jupyter --version` returned an unrecognized version number $v")
return v"0.0"
Expand All @@ -40,16 +40,16 @@ else
end
isconda = dirname(jupyter) == abspath(Conda.SCRIPTDIR)
if Sys.ARCH in (:i686, :x86_64) && (jupyter_vers === nothing || jupyter_vers < v"3.0" || isconda)
isconda || jupyter_vers === nothing || info("$jupyter was too old: got $jupyter_vers, required ≥ 3.0")
info("Installing Jupyter via the Conda package.")
isconda || jupyter_vers === nothing || Compat.@info("$jupyter was too old: got $jupyter_vers, required ≥ 3.0")
Compat.@info("Installing Jupyter via the Conda package.")
Conda.add("jupyter")
jupyter = abspath(Conda.SCRIPTDIR, "jupyter")
jupyter_vers = prog_version(jupyter)
end
if jupyter_vers === nothing || jupyter_vers < v"3.0"
error("Failed to find or install Jupyter 3.0 or later. Please install Jupyter manually, set `ENV[\"JUPYTER\"]=\"/path/to/jupyter\", and rerun `Pkg.build(\"IJulia\")`.")
end
info("Found Jupyter version $jupyter_vers: $jupyter")
Compat.@info("Found Jupyter version $jupyter_vers: $jupyter")

#######################################################################
# Get the latest syntax highlighter file.
Expand Down Expand Up @@ -91,7 +91,7 @@ kspec_cmd, = installkernel("Julia")
# "kernelspec" with "notebook":
notebook = kspec_cmd.exec
n = notebook[end]
ki = rsearch(n, "kernelspec")
ki = VERSION < v"0.7.0-DEV.3252" ? rsearch(n, "kernelspec") : findlast("kernelspec", n)
notebook[end] = n[1:prevind(n,first(ki))] * "notebook" * n[nextind(n,last(ki)):end]

#######################################################################
Expand Down
8 changes: 4 additions & 4 deletions deps/kspec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
copy_config(src, dest) = cp(src, joinpath(dest, basename(src)), remove_destination=true)

"""
installkernel(name, options...; specname=replace(lowercase(name), " ", "-")
installkernel(name, options...; specname=replace(lowercase(name), " "=>"-")
Install a new Julia kernel, where the given `options` are passed to the `julia`
executable, and the user-visible kernel name is given by `name` followed by the
Expand All @@ -31,7 +31,7 @@ run(`\$kernelspec remove -f \$kernelname`)
```
"""
function installkernel(name::AbstractString, julia_options::AbstractString...;
specname::AbstractString = replace(lowercase(name), " ", "-"))
specname::AbstractString = replace(lowercase(name), " "=>"-"))
# 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 @@ -41,7 +41,7 @@ function installkernel(name::AbstractString, julia_options::AbstractString...;
juliakspec = joinpath(tempdir(), spec_name)
try
binary_name = Compat.Sys.iswindows() ? "julia.exe" : "julia"
kernelcmd_array = String[joinpath(JULIA_HOME,"$binary_name"), "-i",
kernelcmd_array = String[joinpath(Compat.Sys.BINDIR,"$binary_name"), "-i",
"--startup-file=yes", "--color=yes"]
append!(kernelcmd_array, julia_options)
ijulia_dir = get(ENV, "IJULIA_DIR", dirname(@__DIR__)) # support non-Pkg IJulia installs
Expand All @@ -65,7 +65,7 @@ function installkernel(name::AbstractString, julia_options::AbstractString...;
copy_config(joinpath(ijulia_dir,"deps","logo-32x32.png"), juliakspec)
copy_config(joinpath(ijulia_dir,"deps","logo-64x64.png"), juliakspec)

info("Installing $name kernelspec $spec_name")
Compat.@info("Installing $name kernelspec $spec_name")

# remove these hacks when
# https://github.com/jupyter/notebook/issues/448 is closed and the fix
Expand Down
13 changes: 12 additions & 1 deletion src/IJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,18 @@ export notebook, installkernel
using ZMQ, JSON, Compat
import Compat.invokelatest
using Compat.Unicode: uppercase, lowercase
import Compat.Dates
using Compat.Dates: now
import Compat.Random

if VERSION v"0.7.0-DEV.2338" # julia#24361
using Base64: Base64EncodePipe
end
if isdefined(Base, :REPL) && !Base.isdeprecated(Base, :REPL)
import Base.REPL
else
import REPL
end

#######################################################################
# Debugging IJulia
Expand Down Expand Up @@ -198,7 +209,7 @@ function clear_history(indices)
end

# since a range could be huge, intersect it with 1:n first
clear_history{T<:Integer}(r::AbstractRange{T}) =
clear_history(r::AbstractRange{T}) where {T<:Integer} =
invoke(clear_history, Tuple{Any}, intersect(r, 1:n))

function clear_history()
Expand Down
6 changes: 3 additions & 3 deletions src/comm_manager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@ import IJulia: Msg, uuid4, send_ipython, msg_pub
export Comm, comm_target, msg_comm, send_comm, close_comm,
register_comm, comm_msg, comm_open, comm_close, comm_info_request

type Comm{target}
mutable struct Comm{target}
id::String
primary::Bool
on_msg::Function
on_close::Function
function (::Type{Comm{target}}){target}(id, primary, on_msg, on_close)
function (::Type{Comm{target}})(id, primary, on_msg, on_close) where {target}
comm = new{target}(id, primary, on_msg, on_close)
comms[id] = comm
return comm
Expand Down Expand Up @@ -42,7 +42,7 @@ function Comm(target,
return comm
end

comm_target{target}(comm :: Comm{target}) = target
comm_target(comm :: Comm{target}) where {target} = target

function comm_info_request(sock, msg)
reply = if haskey(msg.content, "target_name")
Expand Down
44 changes: 20 additions & 24 deletions src/execute_request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

import Base.Libc: flush_cstdio

using Compat

const text_plain = MIME("text/plain")
const image_svg = MIME("image/svg+xml")
const image_png = MIME("image/png")
Expand Down Expand Up @@ -55,16 +53,16 @@ const displayqueue = Any[]
# remove x from the display queue
function undisplay(x)
i = findfirst(equalto(x), displayqueue)
if i > 0
if i !== nothing && i > 0
splice!(displayqueue, i)
end
return x
end

function show_bt(io::IO, top_func::Symbol, t, set)
# follow PR #17570 code in removing top_func from backtrace
eval_ind = findlast(addr->Base.REPL.ip_matches_func(addr, top_func), t)
eval_ind != 0 && (t = t[1:eval_ind-1])
eval_ind = findlast(addr->REPL.ip_matches_func(addr, top_func), t)
eval_ind !== nothing && eval_ind != 0 && (t = t[1:eval_ind-1])
Base.show_backtrace(io, t)
end

Expand All @@ -86,9 +84,9 @@ function error_content(e, bt=catch_backtrace(); backtrace_top::Symbol=:include_s
catch
"SYSTEM: show(lasterr) caused an error"
end
unshift!(tb, evalue) # fperez says this needs to be in traceback too
pushfirst!(tb, evalue) # fperez says this needs to be in traceback too
if !isempty(msg)
unshift!(tb, msg)
pushfirst!(tb, msg)
end
Dict("ename" => ename, "evalue" => evalue,
"traceback" => tb)
Expand All @@ -102,14 +100,10 @@ execute_msg = Msg(["julia"], Dict("username"=>"jlkernel", "session"=>uuid4()), D
# request
const stdio_bytes = Ref(0)

function helpcode(code::AbstractString)
code_ = strip(code)
# as in base/REPL.jl, special-case keywords so that they parse
if !haskey(Docs.keywords, Symbol(code_))
return "Base.Docs.@repl $code_"
else
return "eval(:(Base.Docs.@repl \$(Symbol(\"$code_\"))))"
end
if VERSION < v"0.7.0-DEV.3589" # julia #25738
import Base.Docs: helpmode # added in 0.6, see julia #19858
else
import REPL: helpmode
end

# use a global array to accumulate "payloads" for the execute_reply message
Expand All @@ -133,30 +127,32 @@ function execute_request(socket, msg)
"code" => code)))
end

silent = silent || Base.REPL.ends_with_semicolon(code)
silent = silent || REPL.ends_with_semicolon(code)
if store_history
In[n] = code
end

# "; ..." cells are interpreted as shell commands for run
code = replace(code, r"^\s*;.*$",
code = replace(code, r"^\s*;.*$" =>
m -> string(replace(m, r"^\s*;", "Base.repl_cmd(`"),
"`, STDOUT)"))

# a cell beginning with "? ..." is interpreted as a help request
hcode = replace(code, r"^\s*\?", "")
if hcode != code
code = helpcode(hcode)
end
hcode = replace(code, r"^\s*\?" => "")

try
for hook in preexecute_hooks
invokelatest(hook)
end

#run the code!
ans = result = ismatch(magics_regex, code) ? magics_help(code) :
include_string(current_module[], code, "In[$n]")

if hcode != code # help request
eval(Main, helpmode(hcode))
else
#run the code!
ans = result = contains(code, magics_regex) ? magics_help(code) :
include_string(current_module[], code, "In[$n]")
end

if silent
result = nothing
Expand Down
31 changes: 4 additions & 27 deletions src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ using .CommManager
# due to issue #380. Find the start of the first line
# (if any) where the expression is parseable. Replace
# with find_parsestart(c,p) = start(c) once julia#9467 is merged.
parseok(s) = !Meta.isexpr(parse(s, raise=false), :error)
parseok(s) = !Meta.isexpr(Meta.parse(s, raise=false), :error)
function find_parsestart(code, cursorpos)
s = start(code)
while s < cursorpos
Expand Down Expand Up @@ -197,31 +197,8 @@ function shutdown_request(socket, msg)
exit()
end

stripdots(ex) = :_
stripdots(ex::Symbol) = ex
stripdots(ex::Expr) = Meta.isexpr(ex, :.) ? stripdots(ex.args[2]) : :_
stripdots(ex::QuoteNode) = ex.value
stripdots(ex::GlobalRef) = ex.name
rm_sideeffects(ex) = ex
function rm_sideeffects(ex::Expr)
if Meta.isexpr(ex, :call)
name = stripdots(ex.args[1])
if name == :repl_search || name == :repl_corrections
return nothing
else
return ex
end
else
return Expr(ex.head, map(rm_sideeffects, ex.args)...)
end
end
function docdict(s::AbstractString)
ex = macroexpand(Main, parse(helpcode(s)))
# unfortunately, the REPL help macros sometimes have
# expressions with side effects (I/O), so we need to
# remove these.
display_dict(eval(Main, rm_sideeffects(ex)))
end
docdict(s::AbstractString) = display_dict(eval(Main, helpmode(DevNull, s)))

import Base: is_id_char, is_id_start_char
function get_token(code, pos)
# given a string and a cursor position, find substring to request
Expand Down Expand Up @@ -287,7 +264,7 @@ function history_request(socket, msg)
end

function is_complete_request(socket, msg)
ex = parse(msg.content["code"], raise=false)
ex = Meta.parse(msg.content["code"], raise=false)
status = Meta.isexpr(ex, :incomplete) ? "incomplete" : Meta.isexpr(ex, :error) ? "invalid" : "complete"
send_ipython(requests[],
msg_reply(msg, "is_complete_reply",
Expand Down
12 changes: 8 additions & 4 deletions src/heartbeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
# call in libzmq, which simply blocks forever, so the usual lack of
# thread safety in Julia should not be an issue here.


const threadid = zeros(Int, 128) # sizeof(uv_thread_t) <= 8 on Linux, OSX, Win
const libzmq = ZMQ.zmq

# entry point for new thread
function heartbeat_thread(sock::Ptr{Void})
ccall((:zmq_proxy,ZMQ.libzmq), Cint, (Ptr{Void}, Ptr{Void}, Ptr{Void}),
function heartbeat_thread(sock::Ptr{Cvoid})
ccall((:zmq_proxy,ZMQ.libzmq), Cint, (Ptr{Cvoid}, Ptr{Cvoid}, Ptr{Cvoid}),
sock, sock, C_NULL)
nothing
end

function start_heartbeat(sock)
heartbeat_c = cfunction(heartbeat_thread, Void, Tuple{Ptr{Void}})
ccall(:uv_thread_create, Cint, (Ptr{Int}, Ptr{Void}, Ptr{Void}),
heartbeat_c = cfunction(heartbeat_thread, Cvoid, Tuple{Ptr{Cvoid}})
ccall(:uv_thread_create, Cint, (Ptr{Int}, Ptr{Cvoid}, Ptr{Cvoid}),
threadid, heartbeat_c, sock.data)
end
2 changes: 1 addition & 1 deletion src/hmac.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function hmac(s1,s2,s3,s4)
end
# Take the digest (returned as a byte array) and convert it to hex string representation
digest = MbedTLS.finish!(hmacstate[])
hexdigest = Vector{UInt8}(length(digest)*2)
hexdigest = Vector{UInt8}(uninitialized, length(digest)*2)
for i = 1:length(digest)
b = digest[i]
d = b >> 4
Expand Down
13 changes: 8 additions & 5 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,24 @@ include(joinpath("..","deps","kspec.jl"))

# use our own random seed for msg_id so that we
# don't alter the user-visible random state (issue #336)
const IJulia_RNG = srand(MersenneTwister(0))
uuid4() = repr(Base.Random.uuid4(IJulia_RNG))
const IJulia_RNG = Random.srand(Random.MersenneTwister(0))
@static if VERSION < v"0.7.0-DEV.3666" # julia#25819
uuid4() = repr(Random.uuid4(IJulia_RNG))
else
import UUIDs
uuid4() = repr(UUIDs.uuid4(IJulia_RNG))
end

const orig_STDIN = Ref{IO}()
const orig_STDOUT = Ref{IO}()
const orig_STDERR = Ref{IO}()
function __init__()
srand(IJulia_RNG)
Random.srand(IJulia_RNG)
orig_STDIN[] = STDIN
orig_STDOUT[] = STDOUT
orig_STDERR[] = STDERR
end

const threadid = Vector{Int}(128) # sizeof(uv_thread_t) <= 8 on Linux, OSX, Win

# the following constants need to be initialized in init().
const ctx = Ref{Context}()
const publish = Ref{Socket}()
Expand Down
5 changes: 4 additions & 1 deletion src/inline.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import Base: display, redisplay

immutable InlineDisplay <: Display end
@static if !isdefined(Base, :AbstractDisplay) # remove when Compat.jl#482 is merged and tagged
const AbstractDisplay = Display
end
struct InlineDisplay <: AbstractDisplay end

# supported MIME types for inline display in IPython, in descending order
# of preference (descending "richness")
Expand Down
4 changes: 2 additions & 2 deletions src/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import IJulia

# workaround #60:
if IJulia.Compat.Sys.isapple()
ENV["PATH"] = JULIA_HOME*":"*ENV["PATH"]
ENV["PATH"] = IJulia.Compat.Sys.BINDIR*":"*ENV["PATH"]
end

IJulia.init(ARGS)
Expand All @@ -12,7 +12,7 @@ import IJulia: ans, In, Out, clear_history

pushdisplay(IJulia.InlineDisplay())

ccall(:jl_exit_on_sigint, Void, (Cint,), 0)
ccall(:jl_exit_on_sigint, Cvoid, (Cint,), 0)

# the size of truncated output to show should not depend on the terminal
# where the kernel is launched, since the display is elsewhere
Expand Down
Loading

0 comments on commit 137fcf7

Please sign in to comment.