Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rely less on Requires.jl #478

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ Observables = "510215fc-4207-5dde-b226-833fc4488ee2"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
AssetRegistry = "bf4720bc-e11a-5d0c-854e-bdca1663c893"
UUIDs = "cf7118a7-6976-5b1a-9a39-7adc72f591a4"
Mux = "a975b10e-0019-58db-a62f-e48ff68538c9"
Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b"
Widgets = "cc8bc4a8-27d6-5769-a93b-9d913e69aa62"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand All @@ -25,7 +26,6 @@ Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
JSExpr = "97c1335a-c9c5-57fe-bc5d-ec35cebe8660"
IJulia = "7073ff75-c697-5162-941a-fcdaad2a7d2a"
Mux = "a975b10e-0019-58db-a62f-e48ff68538c9"
Blink = "ad839575-38b3-5650-b840-f874b8c74a25"
NBInclude = "0db19996-df87-5ea3-a455-e3a50d440464"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
Expand All @@ -42,4 +42,4 @@ WebSockets = "1.5.0"
Requires = "0.4.4, 0.5, 1.0.0"

[targets]
test = ["Blink", "Conda", "DataStructures", "Dates", "IJulia", "JSExpr", "Mux", "NBInclude", "Test"]
test = ["Blink", "Conda", "DataStructures", "Dates", "IJulia", "JSExpr", "NBInclude", "Test"]
32 changes: 12 additions & 20 deletions src/WebIO.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import Widgets: node, AbstractWidget
using Logging
using UUIDs
using Base64
using Mux
using WebSockets

include("../deps/bundlepaths.jl")

Expand Down Expand Up @@ -94,35 +96,25 @@ function prefetch_provider_file(basename)
(file = filepath, code = code)
end

provider_mux = prefetch_provider_file("mux.jl")
provider_blink = prefetch_provider_file("blink.jl")
include("providers/mux.jl")
include("providers/generic_http.jl")

provider_ijulia = prefetch_provider_file("ijulia.jl")
provider_generic_http = prefetch_provider_file("generic_http.jl")

function __init__()
push!(Observables.addhandler_callbacks, WebIO.setup_comm)
@require Mux="a975b10e-0019-58db-a62f-e48ff68538c9" begin
include_string(@__MODULE__, provider_mux.code, provider_mux.file)
end
@require Blink="ad839575-38b3-5650-b840-f874b8c74a25" begin
# The latest version of Blink defines their own WebIO integration
# (after https://github.com/JunoLab/Blink.jl/pull/201).
if isdefined(Blink.AtomShell, :initwebio!)
return
end
Base.depwarn(
"Please upgrade Blink for a smoother integration with WebIO.",
:webio_blink_upgrade,

if !isfile(GENERIC_HTTP_BUNDLE_PATH)
error(
"Unable to find WebIO JavaScript bundle for generic HTTP provider; "
* "try rebuilding WebIO (via `Pkg.build(\"WebIO\")`)."
)
include_string(@__MODULE__, provider_blink.code, provider_blink.file)
end
bundle_key[] = AssetRegistry.register(GENERIC_HTTP_BUNDLE_PATH)

@require IJulia="7073ff75-c697-5162-941a-fcdaad2a7d2a" begin
include_string(@__MODULE__, provider_ijulia.code, provider_ijulia.file)
end
@require WebSockets="104b5d7c-a370-577a-8038-80a2059c5097" begin
include_string(@__MODULE__, provider_generic_http.code, provider_generic_http.file)
end

end

end # module
5 changes: 5 additions & 0 deletions src/node.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,10 @@ with some child nodes and additional properties.
The most common type of `Node` is a DOM node. These can be constructed just by
specifying a symbol as the `instanceof` (they are promoted to an instance of
`WebIO.DOM` under the hood).

```jldoctest
julia> using WebIO

julia> Node(:div, Node(:p, "I am a paragraph!", class="important"))
(div
(p { class="important" }
Expand Down Expand Up @@ -60,6 +63,8 @@ type.

# Examples
```jldoctest
julia> using WebIO

julia> repr(WebIO.promote_instanceof(:div))
"WebIO.DOM(:html, :div)"
```
Expand Down
46 changes: 0 additions & 46 deletions src/providers/blink.jl

This file was deleted.

13 changes: 4 additions & 9 deletions src/providers/generic_http.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,8 @@ end
Sockets.send(p::WSConnection, data) = writeguarded(p.sock, JSON.json(data))
Base.isopen(p::WSConnection) = isopen(p.sock)

if !isfile(GENERIC_HTTP_BUNDLE_PATH)
error(
"Unable to find WebIO JavaScript bundle for generic HTTP provider; "
* "try rebuilding WebIO (via `Pkg.build(\"WebIO\")`)."
)
end
const bundle_key = AssetRegistry.register(GENERIC_HTTP_BUNDLE_PATH)
# Ref constant because we need to retreive it in __init__
const bundle_key = Ref{String}("")

include(joinpath(@__DIR__, "..", "..", "deps", "mimetypes.jl"))

Expand Down Expand Up @@ -111,7 +106,7 @@ function WebIOServer(
else # relative url
string("http://", baseurl, ":", http_port, WebIO.baseurl[])
end
string(base, bundle_key)
string(base, bundle_key[])
end
wait_time = 5; start = time() # wait for max 5 s
while time() - start < wait_time
Expand Down Expand Up @@ -144,7 +139,7 @@ function global_server_config()
ws_default = string("ws://", url, ":", http_port, "/webio_websocket/")
ws_url = get(ENV, "WEBIO_WEBSOCKT_URL", ws_default)
# make it possible, to e.g. host the bundle online
bundle_url = get(ENV, "WEBIO_BUNDLE_URL", string(WebIO.baseurl[], bundle_key))
bundle_url = get(ENV, "WEBIO_BUNDLE_URL", string(WebIO.baseurl[], bundle_key[]))
webio_server_config[] = (
url = url, bundle_url = bundle_url,
http_port = http_port, ws_url = ws_url
Expand Down
2 changes: 1 addition & 1 deletion test/http-tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ using Test
@test occursin("_webIOWebSocketURL = ", output)
@test occursin("ws://127.0.0.1:8081/webio_websocket/", output)
@test occursin("""hello, world""", output)
@test WebIO.webio_server_config[] == (url = "127.0.0.1", bundle_url = WebIO.bundle_key, http_port = 8081, ws_url = "ws://127.0.0.1:8081/webio_websocket/")
@test WebIO.webio_server_config[] == (url = "127.0.0.1", bundle_url = WebIO.bundle_key[], http_port = 8081, ws_url = "ws://127.0.0.1:8081/webio_websocket/")
@test isassigned(WebIO.singleton_instance)
end