Permalink
Browse files

Compat writemime, strings, os, startup file with some tests (#434)

* Compat writemime, strings, os, startup file with some tests

* Compat writemime to stringmime
* Compat with strings, dicts
* Compat is_apple, is_windows
* Fixed startup file option
* Added tests for travis, appveyor

* prune compat macro
  • Loading branch information...
1 parent b0b8211 commit 74e6be169a3dcc0c054227f702ada95c139b2557 @wookay wookay committed with stevengj Jul 25, 2016
Showing with 124 additions and 25 deletions.
  1. +1 −0 .gitignore
  2. +7 −0 .travis.yml
  3. +2 −2 REQUIRE
  4. +12 −3 appveyor.yml
  5. +5 −4 deps/build.jl
  6. +4 −2 src/comm_manager.jl
  7. +11 −11 src/execute_request.jl
  8. +5 −1 src/kernel.jl
  9. +2 −1 src/msg.jl
  10. +3 −1 src/stdio.jl
  11. +31 −0 test/comm.jl
  12. +21 −0 test/execute_request.jl
  13. +16 −0 test/msg.jl
  14. +4 −0 test/runtests.jl
View
@@ -4,3 +4,4 @@
/deps/deps.jl
/deps/JUPYTER
/deps/julia-*
+*.jl.*.cov
View
@@ -8,3 +8,10 @@ julia:
- nightly
notifications:
email: false
+script:
+ - if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
+ - julia -e 'Pkg.clone(pwd()); Pkg.build("IJulia")'
+ - julia -e 'Pkg.test("IJulia"; coverage=true)'
+after_success:
+ - julia --color=yes -e 'cd(Pkg.dir("IJulia")); Pkg.add("Coverage"); using Coverage;
+ Coveralls.submit(Coveralls.process_folder())'
View
@@ -1,6 +1,6 @@
julia 0.3
Nettle 0.2
JSON 0.5
-ZMQ 0.3
-Compat 0.7.15
+ZMQ 0.3.1
+Compat 0.7.20
Conda 0.1.5
View
@@ -2,6 +2,8 @@ environment:
matrix:
- JULIAVERSION: "julialang/bin/winnt/x86/0.3/julia-0.3-latest-win32.exe"
- JULIAVERSION: "julialang/bin/winnt/x64/0.3/julia-0.3-latest-win64.exe"
+ - JULIAVERSION: "julialang/bin/winnt/x86/0.4/julia-0.4-latest-win32.exe"
+ - JULIAVERSION: "julialang/bin/winnt/x64/0.4/julia-0.4-latest-win64.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x86/julia-latest-win32.exe"
- JULIAVERSION: "julianightlies/bin/winnt/x64/julia-latest-win64.exe"
@@ -30,6 +32,13 @@ install:
- C:\projects\julia-binary.exe /S /D=C:\projects\julia
build_script:
- - C:\projects\julia\bin\julia -e "versioninfo();
- Pkg.clone(pwd(), \"IJulia\"); Pkg.build(\"IJulia\")"
-# - C:\projects\julia\bin\julia -e "Pkg.test(\"IJulia\")"
+ - C:\projects\julia\bin\julia -F -e "versioninfo(true);
+ Pkg.clone(pwd(), \"IJulia\");
+ using Conda;
+ try Conda.add(\"qt\") end;
+ postlink = normpath(Pkg.dir(\"Conda\"), \"deps/usr/pkgs/qt-4.8.7-vc9_9/Scripts/.qt-post-link.bat\");
+ isfile(postlink) && rm(postlink);
+ Pkg.build(\"IJulia\")"
+
+test_script:
+ - C:\projects\julia\bin\julia -e "Pkg.test(\"IJulia\")"
View
@@ -59,10 +59,11 @@ debugdesc = ccall(:jl_is_debugbuild,Cint,())==1 ? "-debug" : ""
spec_name = "julia-$(VERSION.major).$(VERSION.minor)"*debugdesc
juliakspec = abspath(spec_name)
-binary_name = @windows? "julia.exe":"julia"
+binary_name = is_windows() ? "julia.exe" : "julia"
kernelcmd_array = String[joinpath(JULIA_HOME,("$binary_name")), "-i"]
ijulia_dir = get(ENV, "IJULIA_DIR", Pkg.dir("IJulia")) # support non-Pkg IJulia installs
-append!(kernelcmd_array, ["-F", joinpath(ijulia_dir,"src","kernel.jl"), "{connection_file}"])
+startupfile = VERSION >= v"0.4" ? "--startup-file=yes" : "-F"
+append!(kernelcmd_array, [startupfile, joinpath(ijulia_dir,"src","kernel.jl"), "{connection_file}"])
ks = @compat Dict(
"argv" => kernelcmd_array,
@@ -106,13 +107,13 @@ try
run(`$jupyter kernelspec install --replace --user $juliakspec`)
push!(notebook, jupyter, "notebook")
catch
- @unix_only begin
+ @static if is_unix()
run(`$jupyter-kernelspec install --replace --user $juliakspec`)
push!(notebook, jupyter * "-notebook")
end
# issue #363:
- @windows_only begin
+ @static if is_windows()
jupyter_dir = dirname(jupyter)
jks_exe = ""
if jupyter_dir == abspath(Conda.SCRIPTDIR)
View
@@ -54,10 +54,12 @@ function comm_info_request(sock, msg)
comms
end
- _comms = map(reply) do x
- x[1] => @compat Dict(:target_name, comm_target(x[2]))
+ _comms = Dict{AbstractString, Dict{Symbol,Symbol}}()
+ for (comm_id,comm) in reply
+ _comms[comm_id] = @compat Dict(:target_name => comm_target(comm))
end
content = @compat Dict(:comms => _comms)
+
send_ipython(IJulia.publish,
msg_reply(msg, "comm_info_reply", content))
end
@@ -6,7 +6,9 @@ if VERSION >= v"0.4.0-dev+3844"
import Base.Libc: flush_cstdio
end
-#######################################################################
+using Compat
+import Compat.String
+
const text_plain = MIME("text/plain")
const image_svg = MIME("image/svg+xml")
const image_png = MIME("image/png")
@@ -23,8 +25,7 @@ metadata(x) = Dict()
# return a AbstractString=>AbstractString dictionary of mimetype=>data
# for passing to Jupyter display_data and execute_result messages.
function display_dict(x)
- data = @compat Dict{String,String}("text/plain" =>
- sprint(writemime, "text/plain", x))
+ data = @compat Dict{String,String}("text/plain" => stringmime(text_plain, x))
if mimewritable(image_svg, x)
data[string(image_svg)] = stringmime(image_svg, x)
end
@@ -58,21 +59,20 @@ function undisplay(x)
return x
end
-#######################################################################
-
-if v"0.4.0-dev+6438" <= VERSION < v"0.4.0-dev+6492" # julia PR #12250
- function show_bt(io::IO, top_func::Symbol, t, set)
+function show_bt(io::IO, top_func::Symbol, t, set)
+ if VERSION >= v"0.5.0-pre+5636" # julia PR #17570
+ Base.show_backtrace(io, t)
+ elseif v"0.4.0-dev+6438" <= VERSION < v"0.4.0-dev+6492" # julia PR #12250
process_entry(lastname, lastfile, lastline, n) = Base.show_trace_entry(io, lastname, lastfile, lastline, n)
Base.process_backtrace(process_entry, top_func, t, set)
- end
-else
- show_bt(io::IO, top_func::Symbol, t, set) =
+ else
Base.show_backtrace(io, top_func, t, set)
+ end
end
# return the content of a pyerr message for exception e
function error_content(e, bt=catch_backtrace(); backtrace_top::Symbol=:execute_request_0x535c5df2, msg::AbstractString="")
- tb = map(utf8, @compat(split(sprint(show_bt,
+ tb = map(x->convert(Compat.UTF8String, x), @compat(split(sprint(show_bt,
backtrace_top,
bt, 1:typemax(Int)),
"\n", keep=true)))
View
@@ -1,5 +1,9 @@
+using Compat.is_apple
+
# workaround #60:
-@osx_only ENV["PATH"] = JULIA_HOME*":"*ENV["PATH"]
+if is_apple()
+ ENV["PATH"] = JULIA_HOME*":"*ENV["PATH"]
+end
include("IJulia.jl")
using IJulia
View
@@ -40,7 +40,7 @@ msg_reply(m::Msg, msg_type, content, metadata=Dict{AbstractString,Any}()) =
function show(io::IO, msg::Msg)
print(io, "IPython Msg [ idents ")
- print_joined(io, msg.idents, ", ")
+ print(io, join(msg.idents, ", "))
print(io, " ] {\n parent_header = $(msg.parent_header),\n header = $(msg.header),\n metadata = $(msg.metadata),\n content = $(msg.content)\n}")
end
@@ -64,6 +64,7 @@ end
function recv_ipython(socket)
msg = recv(socket)
idents = AbstractString[]
+ # unsafe_string for ZMQ.jl has patched
s = bytestring(msg)
@vprintln("got msg part $s")
while s != "<IDS|MSG>"
View
@@ -176,7 +176,9 @@ end
function oslibuv_flush()
#refs: https://github.com/JuliaLang/IJulia.jl/issues/347#issuecomment-144505862
# https://github.com/JuliaLang/IJulia.jl/issues/347#issuecomment-144605024
- @windows_only ccall(:SwitchToThread, stdcall, Void, ())
+ @static if is_windows()
+ ccall(:SwitchToThread, stdcall, Void, ())
+ end
yield()
yield()
end
View
@@ -0,0 +1,31 @@
+using Base.Test
+using Compat
+import IJulia: Comm, comm_target
+
+
+target = :notarget
+comm_id = "6BA197D8A67A455196279A59EB2FE844"
+comm = Comm(target, comm_id, false)
+@test :notarget == comm_target(comm)
+@test !comm.primary
+
+
+# comm_info_request in comm_manager.jl
+const comms = @compat Dict{AbstractString, Comm}(
+ "id" => Comm(Symbol("jupyter.widget"), "id", false)
+)
+msg_content = @compat Dict("target_name" => "jupyter.widget")
+reply = if haskey(msg_content, "target_name")
+ t = @compat Symbol(msg_content["target_name"])
+ filter((k, v) -> comm_target(v) == t, comms)
+else
+ comms
+end
+@test Dict{AbstractString,Comm} == typeof(reply)
+_comms = Dict{AbstractString,Dict{Symbol,Symbol}}()
+for (comm_id,comm) in reply
+ _comms[comm_id] = @compat Dict(:target_name => comm_target(comm))
+end
+@test @compat(Dict("id"=>Dict(:target_name=>Symbol("jupyter.widget")))) == _comms
+content = @compat Dict(:comms => _comms)
+@test @compat(Dict(:comms=>Dict("id"=>Dict(:target_name=>Symbol("jupyter.widget"))))) == content
@@ -0,0 +1,21 @@
+using Base.Test
+
+import IJulia: helpcode, error_content
+
+if VERSION < v"0.4.0-dev+2891"
+ @test "Base.@help +" == helpcode("+")
+else
+ @test !haskey(Docs.keywords, :+)
+ @test "Base.Docs.@repl +" == helpcode("+")
+
+ @test haskey(Docs.keywords, :import)
+ if VERSION < v"0.5.0-dev+3831"
+ @test """eval(:(Base.Docs.@repl \$(symbol("import"))))""" == helpcode("import")
+ else
+ @test """eval(:(Base.Docs.@repl \$(Symbol("import"))))""" == helpcode("import")
+ end
+end
+
+
+content = error_content(UndefVarError(:a))
+@test "UndefVarError" == content["ename"]
View
@@ -0,0 +1,16 @@
+using Base.Test
+using Compat
+import IJulia: Msg
+
+idents = ["idents"]
+header = @compat Dict("msg_id"=>"c673eed8-7c36-47f4-82af-df8ec546a87d",
+ "msg_type"=>"comm_msg",
+ "username"=>"username",
+ "version"=>"5.0",
+ "session"=>"980FF7B5F8A24ECF9876A91F38F4EC09")
+content = @compat Dict("comm_id"=>"d733be5d-fd21-4194-95da-db364346f2c9",
+ "data"=>Dict(:value=>Dict("text/plain"=>"10")))
+msg = Msg(idents, header, content)
+
+@test 1 == length(msg.idents)
+@test "c673eed8-7c36-47f4-82af-df8ec546a87d" == msg.header["msg_id"]
View
@@ -0,0 +1,4 @@
+for file in ["comm.jl", "msg.jl", "execute_request.jl"]
+ println(file)
+ include(file)
+end

0 comments on commit 74e6be1

Please sign in to comment.