Skip to content

Commit

Permalink
Merge pull request #169 from JuliaGizmos/rd/v0.7-redux
Browse files Browse the repository at this point in the history
another try at Julia v0.7 support
  • Loading branch information
rdeits authored Aug 17, 2018
2 parents b1f347a + 706e303 commit e65dcd2
Show file tree
Hide file tree
Showing 30 changed files with 139 additions and 174 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@
yarn.lock
node_modules
*.pyc
deps/build.log

25 changes: 17 additions & 8 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,26 @@ language: julia
matrix:
include:
- os: linux
julia: 0.6
julia: 0.7
env: TESTCMD="xvfb-run julia"
# - os: linux
# julia: nightly
# env: TESTCMD="xvfb-run julia"
- os: linux
julia: 1.0
env: TESTCMD="xvfb-run julia"
- os: linux
julia: nightly
env: TESTCMD="xvfb-run julia"
- os: osx
julia: 0.7
env: TESTCMD="julia"
- os: osx
julia: 1.0
env: TESTCMD="julia"
- os: osx
julia: 0.6
julia: nightly
env: TESTCMD="julia"
# - os: osx
# julia: nightly
# env: TESTCMD="julia"
allow_failures:
- julia: nightly

script:
- if [[ -a .git/shallow ]]; then git fetch --unshallow; fi
- $TESTCMD -e 'Pkg.clone(pwd()); Pkg.build("WebIO"); Pkg.test("WebIO"; coverage=true)'
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ cd(Pkg.dir("WebIO", "assets"))

**Development setup** if you want to edit the javascript files in this repository, you will need to setup ways to build them. It's made easy for you:
```julia
pkg"add NodeJS"
using WebIO
WebIO.bundlejs() # run every time you update a file
```
Expand Down
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
julia 0.6
julia 0.7
JSON 0.7
FunctionalCollections
Observables 0.0.3
Expand Down
6 changes: 4 additions & 2 deletions assets/providers/mux_setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@
}

function tryconnect(url) {

var ws = new WebSocket(url + "/webio-socket");
if (url.substring(url.length - 1, url.length) !== "/") {
url += "/"
}
var ws = new WebSocket(url + "webio-socket");
ws.onopen = function () {
WebIO.sendCallback = function (msg) {
ws.send(JSON.stringify(msg))
Expand Down
11 changes: 0 additions & 11 deletions deps/_bundlejs.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,3 @@
# we expect build_dir and assets_dir to be defined here
cd(Pkg.dir()) do
# Install NodeJS if it doesn't exist
reqs = Pkg.Reqs.parse(IOBuffer("NodeJS"))
Pkg.Entry.resolve(merge(Pkg.Reqs.parse("REQUIRE"), reqs))
end

using NodeJS

cd(joinpath(dirname(@__FILE__), "..", "assets", "webio")) do
Expand All @@ -19,7 +12,3 @@ cd(joinpath(dirname(@__FILE__), "..", "assets", "webio")) do
end
run(`$npm run build --scripts-prepend-node-path -- $args`)
end

cd(Pkg.dir()) do
Pkg.Entry.resolve() # Uninstall NodeJS if it wasn't there before
end
5 changes: 1 addition & 4 deletions deps/build.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ function install_ijulia_config()
end

# remove previous config
config_str = replace(config_str, Regex("\n?" * BEGIN_MARKER * ".*" * END_MARKER * "\n?", "s"), "")
config_str = replace(config_str, Regex("\n?" * BEGIN_MARKER * ".*" * END_MARKER * "\n?", "s") => "")

loadpath = JSON.json(vcat(Pkg.dir(), LOAD_PATH))
config_str *= """
$BEGIN_MARKER
Expand Down Expand Up @@ -48,8 +47,6 @@ function install_ijulia_config()
end
end
@label jsondone

write("load_paths.json", loadpath)
end

install_ijulia_config()
61 changes: 20 additions & 41 deletions deps/jlstaticserve.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,57 +18,36 @@ def set_extra_headers(self, path):

@gen.coroutine
def get(self, pkg, fpath):
if pkg != "assetserver":
# old server
dirs = self.julia_load_path
for d in dirs:
dirpath = os.path.join(d, pkg, "assets")
fullpath = os.path.join(dirpath, fpath)
if os.path.isdir(dirpath) and os.path.isfile(fullpath):
self.root = dirpath
yield StaticFileHandler.get(self, fpath)
break
else:
# will execute only if the `for` loop never `break`s
raise HTTPError(404)
homedir = os.path.expanduser("~")
data = {}
registry = os.path.join(homedir, ".jlassetregistry.json")
if not os.path.isfile(registry):
raise HTTPError(404)
with open(registry, "r") as assets_file:
data = json.load(assets_file)
parts = fpath.split("/", 1)
if len(parts) > 1:
sha = parts[0]
else:
homedir = os.path.expanduser("~")
data = {}
registry = os.path.join(homedir, ".jlassetregistry.json")
if not os.path.isfile(registry):
raise HTTPError(404)
with open(registry, "r") as assets_file:
data = json.load(assets_file)
parts = fpath.split("/", 1)
sha = fpath
key = "/assetserver/" + sha
if key in data:
f = data[key][0]
if len(parts) > 1:
sha = parts[0]
else:
sha = fpath
key = "/assetserver/" + sha
if key in data:
f = data[key][0]
if len(parts) > 1:
self.root = f
f = os.path.join(f, parts[1])
else:
self.root = os.path.dirname(f)
yield StaticFileHandler.get(self, f)
self.root = f
f = os.path.join(f, parts[1])
else:
raise HTTPError(404)
self.root = os.path.dirname(f)
yield StaticFileHandler.get(self, f)
else:
raise HTTPError(404)

def load_jupyter_server_extension(nb_server_app):
"""
Extension to serve files from Pkg/assets/
"""
web_app = nb_server_app.web_app
host_pattern = '.*$'
route_pattern_old = url_path_join(web_app.settings['base_url'], '/pkg/([^/]+)/(.*)$')
route_pattern = url_path_join(web_app.settings['base_url'], '/(assetserver)/(.*)$')
with open(os.path.join(os.path.dirname(__file__), "load_paths.json"), "r") as paths_file:
JuliaPackageAssetServer.julia_load_path = json.load(paths_file)
print("Will serve asset files from any Julia package under", JuliaPackageAssetServer.julia_load_path)
web_app.add_handlers(
host_pattern, [(route_pattern_old, JuliaPackageAssetServer)])

web_app.add_handlers(
host_pattern, [(route_pattern, JuliaPackageAssetServer)])
6 changes: 3 additions & 3 deletions examples/counter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,12 @@ end

# Display in whatever frontend is avalaible
function main()
if isdefined(:IJulia) || isdefined(:Juno)
if @isdefined(IJulia) || @isdefined(Juno)
return counter(1)
elseif isdefined(:Blink)
elseif @isdefined(Blink)
win = Window()
body!(win, counter(1))
elseif isdefined(:Mux)
elseif @isdefined(Mux)
@sync webio_serve(page("/", req -> counter(1)), rand(8000:9000))
else
error("do one of using Mux, using Blink before running the
Expand Down
1 change: 1 addition & 0 deletions examples/jupyter-demo.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@
"metadata": {},
"outputs": [],
"source": [
"using Dates\n",
"w = Scope()\n",
"obs = Observable(w, \"clock-value\", \"\")\n",
"\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/p5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ end

# Display in whatever frontend is avalaible
function main()
if isdefined(:IJulia) || isdefined(:Juno)
if @isdefined(IJulia) || @isdefined(Juno)
return hue_app()
elseif isdefined(:Blink)
elseif @isdefined(Blink)
win = Window()
body!(win, hue_app())
win
elseif isdefined(:Mux)
elseif @isdefined(Mux)
@sync webio_serve(page("/", req -> hue_app()), rand(8000:9000))
else
error("do one of using Mux, using Blink before running the
Expand Down
21 changes: 14 additions & 7 deletions src/WebIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module WebIO
using Observables
using Requires
using AssetRegistry
using Compat
using Base64: stringmime
import Widgets: node

abstract type AbstractConnection end
Expand All @@ -28,11 +28,6 @@ in IJulia, this causes the frontend to load the webio javascript bundle.
setup_provider(s::Union{Symbol, AbstractString}) = setup_provider(Val(Symbol(s)))
export setup_provider

include(joinpath("providers", "atom.jl"))
include(joinpath("providers", "blink.jl"))
include(joinpath("providers", "mux.jl"))
include(joinpath("providers", "ijulia.jl"))

const baseurl = Ref{String}("")

function setbaseurl!(str)
Expand All @@ -54,8 +49,20 @@ function setup(provider::Symbol)
end
setup(provider::AbstractString) = setup(Symbol(provider))

Requires.@init begin
function __init__()
push!(Observables.addhandler_callbacks, WebIO.setup_comm)
@require Mux="a975b10e-0019-58db-a62f-e48ff68538c9" begin
include(joinpath("providers", "mux.jl"))
end
@require Juno="e5e0dc1b-0480-54bc-9374-aad01c23163d" begin
include(joinpath("providers", "atom.jl"))
end
@require Blink="ad839575-38b3-5650-b840-f874b8c74a25" begin
include(joinpath("providers", "blink.jl"))
end
@require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
include(joinpath("providers", "ijulia.jl"))
end
end

end # module
4 changes: 2 additions & 2 deletions src/connection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ end

function logmsg(msg, level="info", data=nothing)
if level == "error" || level == "warn"
warn(msg)
@warn(msg)
else
info(msg)
@info(msg)
end

Dict("type"=>"log", "message"=>msg, "level"=>level, data=>data)
Expand Down
2 changes: 1 addition & 1 deletion src/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function lowerdeps(name, imp)
while true
if AssetRegistry.isregistered(cur_path) && isdir(cur_path)
key = AssetRegistry.getkey(cur_path)
url = baseurl[] * key * "/" * replace(path, cur_path, "")
url = baseurl[] * key * "/" * replace(path, cur_path => "")
break
end
cur_path1 = dirname(cur_path)
Expand Down
14 changes: 7 additions & 7 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ a javascript string, the html parser will still read them as a closing script
tag, and thus end the script content prematurely, causing untold woe.
"""
encode_scripts(htmlstr::String) =
replace(htmlstr, "</script>", "</_script>")
replace(htmlstr, "</script>" => "</_script>")

function kwargs2props(propkwargs)
props = Dict{Symbol,Any}(propkwargs)
Expand Down Expand Up @@ -89,7 +89,7 @@ function JSON.lower(n::Node)
"nodeType" => nodetype(n),
"instanceArgs" => JSON.lower(n.instanceof),
"children" => map!(render,
Vector{Any}(length(children(n))),
Vector{Any}(undef, length(children(n))),
children(n)),
"props" => props(n),
)
Expand All @@ -98,11 +98,11 @@ end
## TODO -- optimize
function escapeHTML(i::String)
# Refer to http://stackoverflow.com/a/7382028/3822752 for spec. links
o = replace(i, "&", "&amp;")
o = replace(o, "\"", "&quot;")
o = replace(o, "'", "&#39;")
o = replace(o, "<", "&lt;")
o = replace(o, ">", "&gt;")
o = replace(i, "&" => "&amp;")
o = replace(o, "\"" => "&quot;")
o = replace(o, "'" => "&#39;")
o = replace(o, "<" => "&lt;")
o = replace(o, ">" => "&gt;")
return o
end

Expand Down
20 changes: 7 additions & 13 deletions src/providers/atom.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
@require Juno begin

using Juno

function get_page(opts::Dict=Dict())
Juno.isactive() ? Juno.Atom.blinkplot() : Window(opts).content
end
Expand All @@ -13,19 +9,17 @@ Juno.render(i::Juno.Editor, n::Union{Node, Scope}) =
Juno.render(i, Text("$(n.instanceof) Node with $(n._descendants_count) descendent(s)"))

function WebIO.register_renderable(T::Type, ::Val{:atom})
media(T, Media.Graphical)
Media.render(::Juno.PlotPane, x::T) =
(body!(get_page(), WebIO.render(x)); nothing)
Juno.media(T, Juno.Media.Graphical)
eval(:(Juno.Media.render(::Juno.PlotPane, x::$T) =
(body!(get_page(), WebIO.render(x)); nothing)))
if method_exists(WebIO.render_inline, (T,))
Juno.render(i::Juno.Editor, x::T) =
Juno.render(i, WebIO.render_inline(x))
eval(:(Juno.render(i::Juno.Editor, x::$T) =
Juno.render(i, WebIO.render_inline(x))))
end
end

function WebIO.setup_provider(::Val{:atom})
media(Node, Media.Graphical)
media(Scope, Media.Graphical)
Juno.media(Node, Juno.Media.Graphical)
Juno.media(Scope, Juno.Media.Graphical)
end
WebIO.setup(:atom)

end
Loading

0 comments on commit e65dcd2

Please sign in to comment.