Skip to content

Commit

Permalink
fix more deprecations and a crash in heartbeat
Browse files Browse the repository at this point in the history
  • Loading branch information
stevengj committed Jun 7, 2018
1 parent 9bba2a6 commit bbdebe9
Show file tree
Hide file tree
Showing 13 changed files with 51 additions and 48 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -186,11 +186,11 @@ is `IJulia.load("filename")`.

### Prompting for user input

When you are running in a notebook, ordinary I/O functions on `STDIN` do
When you are running in a notebook, ordinary I/O functions on `stdin` do
not function. However, you can prompt for the user to enter a string
in one of two ways:

* `readline()` and `readline(STDIN)` both open a `STDIN>` prompt widget where the user can enter a string, which is returned by `readline`.
* `readline()` and `readline(stdin)` both open a `stdin>` prompt widget where the user can enter a string, which is returned by `readline`.

* `IJulia.readprompt(prompt)` displays the prompt string `prompt` and
returns a string entered by the user. `IJulia.readprompt(prompt, password=true)` does the same thing but hides the text the user types.
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.17
ZMQ 0.6.0
Compat 0.47.0
Compat 0.68.0
Conda 0.1.5
2 changes: 1 addition & 1 deletion deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ end
# Warn people upgrading from older IJulia versions:
try
juliaprof = chomp(read(pipeline(`$ipython locate profile julia`,
stderr=DevNull), String))
stderr=devnull), String))
warn("""You should now run IJulia just via `$jupyter notebook`, without
the `--profile julia` flag. IJulia no longer maintains the profile.
Consider deleting $juliaprof""")
Expand Down
4 changes: 2 additions & 2 deletions src/IJulia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ function history(io::IO, indices::AbstractVector{Int})
end

history(io::IO, x::Union{Integer,AbstractVector{Int}}...) = history(io, vcat(x...))
history(x...) = history(STDOUT, x...)
history(x...) = history(stdout, x...)
history(io::IO, x...) = throw(MethodError(history, (x...,)))
history() = history(1:n)
"""
Expand All @@ -256,7 +256,7 @@ The optional `indices` argument is one or more indices or collections
of indices indicating a subset input cells to print.
The optional `io` argument is for specifying an output stream. The default
is `STDOUT`.
is `stdout`.
"""
history

Expand Down
2 changes: 1 addition & 1 deletion src/eventloop.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ function eventloop(socket)
# kernel interruption to interrupt long calculations.)
if !isa(e, InterruptException)
content = error_content(e, msg="KERNEL EXCEPTION")
map(s -> println(orig_STDERR[], s), content["traceback"])
map(s -> println(orig_stderr[], s), content["traceback"])
send_ipython(publish[], msg_pub(execute_msg, "error", content))
end
finally
Expand Down
28 changes: 15 additions & 13 deletions src/execute_request.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,27 @@ metadata(x) = Dict()
# for passing to Jupyter display_data and execute_result messages.
function display_dict(x)
data = Dict{String,Any}("text/plain" => limitstringmime(text_plain, x))
if mimewritable(application_vnd_vegalite_v2, x)
if showable(application_vnd_vegalite_v2, x)
data[string(application_vnd_vegalite_v2)] = JSON.JSONText(limitstringmime(application_vnd_vegalite_v2, x))
end
if mimewritable(application_vnd_dataresource, x)
if showable(application_vnd_dataresource, x)
data[string(application_vnd_dataresource)] = JSON.JSONText(limitstringmime(application_vnd_dataresource, x))
end
if mimewritable(image_svg, x)
if showable(image_svg, x)
data[string(image_svg)] = limitstringmime(image_svg, x)
end
if mimewritable(image_png, x)
if showable(image_png, x)
data[string(image_png)] = limitstringmime(image_png, x)
elseif mimewritable(image_jpeg, x) # don't send jpeg if we have png
elseif showable(image_jpeg, x) # don't send jpeg if we have png
data[string(image_jpeg)] = limitstringmime(image_jpeg, x)
end
if mimewritable(text_markdown, x)
if showable(text_markdown, x)
data[string(text_markdown)] = limitstringmime(text_markdown, x)
elseif mimewritable(text_html, x)
elseif showable(text_html, x)
data[string(text_html)] = limitstringmime(text_html, x)
elseif mimewritable(text_latex, x)
elseif showable(text_latex, x)
data[string(text_latex)] = limitstringmime(text_latex, x)
elseif mimewritable(text_latex2, x)
elseif showable(text_latex2, x)
data[string(text_latex)] = limitstringmime(text_latex2, x)
end
return data
Expand All @@ -56,7 +56,7 @@ const displayqueue = Any[]

# remove x from the display queue
function undisplay(x)
i = findfirst(equalto(x), displayqueue)
i = findfirst(isequal(x), displayqueue)
if i !== nothing && i > 0
splice!(displayqueue, i)
end
Expand Down Expand Up @@ -113,6 +113,8 @@ end
# use a global array to accumulate "payloads" for the execute_reply message
const execute_payloads = Dict[]

const stdout_name = isdefined(Base, :stdout) ? "stdout" : "STDOUT"

function execute_request(socket, msg)
code = msg.content["code"]
@vprintln("EXECUTING ", code)
Expand All @@ -139,7 +141,7 @@ function execute_request(socket, msg)
# "; ..." cells are interpreted as shell commands for run
code = replace(code, r"^\s*;.*$" =>
m -> string(replace(m, r"^\s*;", "Base.repl_cmd(`"),
"`, STDOUT)"))
"`, ", stdout_name, ")"))

# a cell beginning with "? ..." is interpreted as a help request
hcode = replace(code, r"^\s*\?" => "")
Expand All @@ -151,10 +153,10 @@ function execute_request(socket, msg)


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

Expand Down
4 changes: 2 additions & 2 deletions src/handlers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ function complete_types(comps)
expr = Meta.parse(c, raise=false)
if typeof(expr) == Symbol
try
ctype = complete_type(eval(current_module[], :(typeof($expr))))
ctype = complete_type(Core.eval(current_module[], :(typeof($expr))))
end
elseif !isa(expr, Expr)
ctype = complete_type(expr)
Expand Down Expand Up @@ -200,7 +200,7 @@ function shutdown_request(socket, msg)
exit()
end

docdict(s::AbstractString) = display_dict(eval(Main, helpmode(DevNull, s)))
docdict(s::AbstractString) = display_dict(Core.eval(Main, helpmode(devnull, s)))

import Base: is_id_char, is_id_start_char
function get_token(code, pos)
Expand Down
5 changes: 3 additions & 2 deletions src/heartbeat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@


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

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

function start_heartbeat(sock)
heartbeat_c = cfunction(heartbeat_thread, Cvoid, Tuple{Ptr{Cvoid}})
heartbeat_c = @cfunction(heartbeat_thread, Cvoid, (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}(uninitialized, length(digest)*2)
hexdigest = Vector{UInt8}(undef, length(digest)*2)
for i = 1:length(digest)
b = digest[i]
d = b >> 4
Expand Down
18 changes: 9 additions & 9 deletions src/init.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ else
uuid4() = repr(UUIDs.uuid4(IJulia_RNG))
end

const orig_STDIN = Ref{IO}()
const orig_STDOUT = Ref{IO}()
const orig_STDERR = Ref{IO}()
const orig_stdin = Ref{IO}()
const orig_stdout = Ref{IO}()
const orig_stderr = Ref{IO}()
function __init__()
Random.srand(IJulia_RNG)
orig_STDIN[] = STDIN
orig_STDOUT[] = STDOUT
orig_STDERR[] = STDERR
orig_stdin[] = stdin
orig_stdout[] = stdout
orig_stderr[] = stderr
end

# the following constants need to be initialized in init().
Expand Down Expand Up @@ -103,13 +103,13 @@ function init(args)
start_heartbeat(heartbeat[])
if capture_stdout
read_stdout[], = redirect_stdout()
redirect_stdout(IJuliaStdio(STDOUT,"stdout"))
redirect_stdout(IJuliaStdio(stdout,"stdout"))
end
if capture_stderr
read_stderr[], = redirect_stderr()
redirect_stderr(IJuliaStdio(STDERR,"stderr"))
redirect_stderr(IJuliaStdio(stderr,"stderr"))
end
redirect_stdin(IJuliaStdio(STDIN,"stdin"))
redirect_stdin(IJuliaStdio(stdin,"stdin"))

send_status("starting")
global inited = true
Expand Down
4 changes: 2 additions & 2 deletions src/kernel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ ccall(:jl_exit_on_sigint, IJulia.Compat.Cvoid, (Cint,), 0)
ENV["LINES"] = get(ENV, "LINES", 30)
ENV["COLUMNS"] = get(ENV, "COLUMNS", 80)

println(IJulia.orig_STDOUT[], "Starting kernel event loops.")
println(IJulia.orig_stdout[], "Starting kernel event loops.")
IJulia.watch_stdio()

# workaround JuliaLang/julia#4259
delete!(task_local_storage(),:SOURCE_PATH)

# workaround JuliaLang/julia#6765
eval(Base, :(is_interactive = true))
Core.eval(Base, :(is_interactive = true))

IJulia.waitloop()
8 changes: 4 additions & 4 deletions src/magics.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ alias_magic_help(magic::AbstractString, args::AbstractString) = md"""
which you can then run with e.g. `bracket("hello world")`."""

function cd_magic_help(magic::AbstractString, args::AbstractString)
if magic == "%cd" && !contains(args, r"\s*-")
if magic == "%cd" && !occursin(r"\s*-", args)
return md"""The equivalent of `%cd 'dir'` in IPython is `cd("dir")` in Julia."""
else
return md"""
Expand Down Expand Up @@ -217,7 +217,7 @@ prun_magic_help(magic::AbstractString, args::AbstractString) = md"""

psearch_magic_help(magic::AbstractString, args::AbstractString) = md"""
A rough analogue of IPython's `%psearch PATTERN` in Julia might be
`filter(s -> contains(string(s), r"PATTERN"), names(Base))`, which
`filter(s -> occursin(r"PATTERN", string(s)), names(Base))`, which
searches all the symbols defined in the `Base` module for a given
regular-expression pattern `PATTERN`."""

Expand Down Expand Up @@ -349,7 +349,7 @@ function pipe_magic_help(magic::AbstractString, args::AbstractString)
The analogue of IPython's `$magic ...code...` in Julia can be
constructed by first evaluating
```
macro $(cmd)_str(s) open(`$cmd`,"w",STDOUT) do io; print(io, s); end; end
macro $(cmd)_str(s) open(`$cmd`,"w",stdout) do io; print(io, s); end; end
```
to define the `$cmd"...."` [string macro](http://docs.julialang.org/en/latest/manual/strings/#non-standard-string-literals)
in Julia. Subsequently, you can simply do:
Expand All @@ -358,7 +358,7 @@ function pipe_magic_help(magic::AbstractString, args::AbstractString)
...code...
""\"
```
to evaluate the code in `$cmd` (outputting to `STDOUT`).""")
to evaluate the code in `$cmd` (outputting to `stdout`).""")
end

svg_magic_help(magic::AbstractString, args::AbstractString) = md"""
Expand Down
16 changes: 8 additions & 8 deletions src/stdio.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# IJulia redirects STDOUT and STDERR into "stream" messages sent to the
# IJulia redirects stdout and stderr into "stream" messages sent to the
# Jupyter front-end.

# create a wrapper type around redirected stdio streams,
Expand Down Expand Up @@ -30,7 +30,7 @@ for s in ("stdout", "stderr", "stdin")
S = QuoteNode(Symbol(uppercase(s)))
@eval function Base.$f(io::IJuliaStdio)
io[:jupyter_stream] != $s && throw(ArgumentError(string("expecting ", $s, " stream")))
eval(Base, Expr(:(=), $S, io))
Core.eval(Base, Expr(:(=), $S, io))
return io
end
end
Expand All @@ -49,15 +49,15 @@ end
macro vprintln(x...)
quote
if verbose::Bool
println(orig_STDOUT[], get_log_preface(), $(map(esc, x)...))
println(orig_stdout[], get_log_preface(), $(map(esc, x)...))
end
end
end

macro verror_show(e, bt)
quote
if verbose::Bool
showerror(orig_STDERR[], $(esc(e)), $(esc(bt)))
showerror(orig_stderr[], $(esc(e)), $(esc(bt)))
end
end
end
Expand Down Expand Up @@ -216,7 +216,7 @@ end
import Base.readline
function readline(io::IJuliaStdio)
if get(io,:jupyter_stream,"unknown") == "stdin"
return readprompt("STDIN> ")
return readprompt("stdin> ")
else
readline(io.io)
end
Expand All @@ -232,7 +232,7 @@ function watch_stdio()
task_local_storage(:IJulia_task, "init task")
if capture_stdout
read_task = @async watch_stream(read_stdout[], "stdout")
#send STDOUT stream msgs every stream_interval secs (if there is output to send)
#send stdout stream msgs every stream_interval secs (if there is output to send)
_Timer(send_stdout, stream_interval, stream_interval)
end
if capture_stderr
Expand All @@ -244,8 +244,8 @@ end

function flush_all()
flush_cstdio() # flush writes to stdout/stderr by external C code
flush(STDOUT)
flush(STDERR)
flush(stdout)
flush(stderr)
end

function oslibuv_flush()
Expand Down

0 comments on commit bbdebe9

Please sign in to comment.