From cc9839184f9ae4188e4d4ff41ca46d230aeda372 Mon Sep 17 00:00:00 2001 From: Robin Deits Date: Sat, 21 Jul 2018 02:24:59 -0400 Subject: [PATCH] fix most 0.7 deprecations and errors --- deps/build.jl | 4 ++-- src/AtomShell/AtomShell.jl | 4 +++- src/AtomShell/install.jl | 14 +++++++------- src/AtomShell/process.jl | 33 +++++++++++++++++++++------------ src/AtomShell/window.jl | 8 ++++---- src/Blink.jl | 7 +++++-- src/content/config.jl | 8 ++++---- src/content/content.jl | 4 ++-- src/rpc/jsexprs.jl | 2 +- src/rpc/rpc.jl | 4 ++-- test/runtests.jl | 4 +++- 11 files changed, 54 insertions(+), 38 deletions(-) diff --git a/deps/build.jl b/deps/build.jl index 835cc59..3962dfa 100644 --- a/deps/build.jl +++ b/deps/build.jl @@ -4,10 +4,10 @@ module BuildBlink include(joinpath(@__DIR__, "../src/AtomShell/install.jl")) function get_installed_version() - _path = is_apple() ? + _path = isapple() ? joinpath(folder(), "version") : joinpath(folder(), "atom", "version") - strip(readstring(_path), 'v') + strip(read(_path, String), 'v') end if isinstalled() && !(version == get_installed_version()) diff --git a/src/AtomShell/AtomShell.jl b/src/AtomShell/AtomShell.jl index b790c9e..718a54e 100644 --- a/src/AtomShell/AtomShell.jl +++ b/src/AtomShell/AtomShell.jl @@ -1,6 +1,8 @@ module AtomShell -using Compat; import Compat.String +using Compat +using Compat.Sockets +using Compat.Sys: isapple, isunix, islinux, iswindows abstract type Shell end diff --git a/src/AtomShell/install.jl b/src/AtomShell/install.jl index 890802d..e60c4ce 100644 --- a/src/AtomShell/install.jl +++ b/src/AtomShell/install.jl @@ -6,21 +6,21 @@ const version = "1.8.6" folder() = normpath(joinpath(@__FILE__, "../../../deps")) -@static if is_apple() +@static if isapple() uninstall() = map(rm′, filter(x -> !endswith(x, "build.jl"), readdir(folder()))) else uninstall() = rm′(joinpath(folder(), "atom")) end -isinstalled() = is_apple() ? +isinstalled() = isapple() ? isfile(joinpath(folder(), "version")) : isdir(joinpath(folder(), "atom")) function install() dir = folder() - if is_apple() - const _icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns")) + if isapple() + _icons = normpath(joinpath(@__FILE__, "../../../res/julia-icns.icns")) end !isdir(dir) && mkpath(dir) uninstall() @@ -29,7 +29,7 @@ function install() download("http://junolab.s3.amazonaws.com/blink/julia.png") - if is_apple() + if isapple() file = "electron-v$version-darwin-x64.zip" download("https://github.com/electron/electron/releases/download/v$version/$file") run(`unzip -q $file`) @@ -41,7 +41,7 @@ function install() run(`touch Julia.app`) # Apparently this is necessary to tell the OS to double-check for the new icons. end - if is_windows() + if iswindows() arch = Int == Int64 ? "x64" : "ia32" file = "electron-v$version-win32-$arch.zip" download("https://github.com/electron/electron/releases/download/v$version/$file") @@ -49,7 +49,7 @@ function install() rm(file) end - if is_linux() + if islinux() arch = Int == Int64 ? "x64" : "ia32" file = "electron-v$version-linux-$arch.zip" download("https://github.com/electron/electron/releases/download/v$version/$file") diff --git a/src/AtomShell/process.jl b/src/AtomShell/process.jl index cc086c6..bb14845 100644 --- a/src/AtomShell/process.jl +++ b/src/AtomShell/process.jl @@ -1,12 +1,21 @@ using Lazy, JSON, MacroTools hascommand(c) = - try readstring(`which $c`); true catch e false end + try read(`which $c`, String); true catch e false end spawn_rdr(cmd) = spawn(cmd, Base.spawn_opts_inherit()...) -resolve(pkg, path...) = - joinpath(Base.find_in_path(pkg, nothing), "..","..", path...) |> normpath +""" + resolve_blink_asset(path...) + +Find a file, expressed as a relative path from the Blink package +folder. Example: + + resolve_blink_asset("src", "Blink.jl") -> /home//.julia/v0.6/Blink/src/Blink.jl +""" +resolve_blink_asset(path...) = joinpath(@__DIR__, "..", "..", path...) + +@deprecate resolve(pkg, path...) resolve_blink_asset(path...) # node-inspector @@ -27,11 +36,11 @@ end # atom-shell -import Base: Process, TCPSocket +import Base: Process export Electron -type Electron <: Shell +mutable struct Electron <: Shell proc::Process sock::TCPSocket handlers::Dict{String, Any} @@ -39,14 +48,14 @@ end Electron(proc, sock) = Electron(proc, sock, Dict()) -@static if is_apple() - const _electron = resolve("Blink", "deps/Julia.app/Contents/MacOS/Julia") -elseif is_linux() - const _electron = resolve("Blink", "deps/atom/electron") -elseif is_windows() - const _electron = resolve("Blink", "deps", "atom", "electron.exe") +@static if isapple() + const _electron = resolve_blink_asset("deps/Julia.app/Contents/MacOS/Julia") +elseif islinux() + const _electron = resolve_blink_asset("deps/atom/electron") +elseif iswindows() + const _electron = resolve_blink_asset("deps", "atom", "electron.exe") end -const mainjs = resolve("Blink", "src", "AtomShell", "main.js") +const mainjs = resolve_blink_asset("src", "AtomShell", "main.js") function electron() path = get(ENV, "ELECTRON_PATH", _electron) diff --git a/src/AtomShell/window.jl b/src/AtomShell/window.jl index 9692021..6512af8 100644 --- a/src/AtomShell/window.jl +++ b/src/AtomShell/window.jl @@ -19,17 +19,17 @@ const window_defaults = @d(:url => "about:blank", :title => "Julia", "node-integration" => false, "use-content-size" => true, - :icon => resolve("Blink", "deps", "julia.png")) + :icon => resolve_blink_asset("deps", "julia.png")) raw_window(a::Electron, opts) = @js a createWindow($(merge(window_defaults, opts))) -function Window(a::Shell, opts::Associative = Dict()) +function Window(a::Shell, opts::AbstractDict = Dict()) return haskey(opts, :url) ? Window(raw_window(a, opts), a, nothing) : Window(a, Page(), opts) end -function Window(a::Shell, content::Page, opts::Associative = Dict()) +function Window(a::Shell, content::Page, opts::AbstractDict = Dict()) opts = merge(opts, Dict(:url => Blink.localurl(content))) return Window(raw_window(a, opts), a, content) end @@ -119,7 +119,7 @@ close(win::Window) = # Window content APIs -active(::Void) = false +active(::Nothing) = false handlers(w::Window) = handlers(w.content) diff --git a/src/Blink.jl b/src/Blink.jl index 1fd5603..d215760 100644 --- a/src/Blink.jl +++ b/src/Blink.jl @@ -3,7 +3,10 @@ __precompile__() module Blink using Reexport -using Compat; import Compat.String +using Compat +using Compat.Distributed: Future +using Compat.Sys: isunix, islinux, isapple, iswindows +using Compat.Sockets include("rpc/rpc.jl") include("content/content.jl") @@ -11,6 +14,6 @@ include("content/content.jl") include("AtomShell/AtomShell.jl") export AtomShell @reexport using .AtomShell -import .AtomShell: resolve +import .AtomShell: resolve_blink_asset end # module diff --git a/src/content/config.jl b/src/content/config.jl index 861f650..92344a3 100644 --- a/src/content/config.jl +++ b/src/content/config.jl @@ -4,7 +4,7 @@ export localips const ippat = r"([0-9]+\.){3}[0-9]+" -@static if is_unix() +@static if isunix() localips() = map(IPv4, readlines(`ifconfig` |> `grep -Eo $("inet (addr:)?$(ippat.pattern)")` |> `grep -Eo $(ippat.pattern)` |> @@ -13,11 +13,11 @@ end # Browser Window -@static if is_apple() +@static if isapple() launch(x) = run(`open $x`) -elseif is_linux() +elseif islinux() launch(x) = run(`xdg-open $x`) -elseif is_windows() +elseif iswindows() launch(x) = run(`cmd /C start $x`) end diff --git a/src/content/content.jl b/src/content/content.jl index e8f6106..adfa0e1 100644 --- a/src/content/content.jl +++ b/src/content/content.jl @@ -6,7 +6,7 @@ include("api.jl") # Content -type Page +mutable struct Page id::Int sock::WebSocket handlers::Dict{String, Any} @@ -52,5 +52,5 @@ end include("server.jl") @init for r in ["blink.js", "blink.css", "reset.css", "spinner.css"] - resource(resolve("Blink", "res", r)) + resource(resolve_blink_asset("res", r)) end diff --git a/src/rpc/jsexprs.jl b/src/rpc/jsexprs.jl index 819b80b..58326e3 100644 --- a/src/rpc/jsexprs.jl +++ b/src/rpc/jsexprs.jl @@ -3,7 +3,7 @@ export JSString jsexpr(io, x) = JSON.print(io, x) -type JSString +mutable struct JSString s::String end diff --git a/src/rpc/rpc.jl b/src/rpc/rpc.jl index 02b42c0..5c46361 100644 --- a/src/rpc/rpc.jl +++ b/src/rpc/rpc.jl @@ -11,7 +11,7 @@ include("jsexprs.jl") include("callbacks.jl") -type JSError <: Exception +mutable struct JSError <: Exception name::String msg::String end @@ -36,7 +36,7 @@ function js(o, js::JSString; callback = true) if callback val = wait(cond) - if isa(val, Associative) && get(val, "type", "") == "error" + if isa(val, AbstractDict) && get(val, "type", "") == "error" err = JSError(get(val, "name", "unknown"), get(val, "message", "blank")) throw(err) end diff --git a/test/runtests.jl b/test/runtests.jl index ed0caef..63a71e7 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,5 +1,7 @@ using Blink -using Base.Test +using Compat.Test +using Compat.Sockets + cleanup = !AtomShell.isinstalled()