Skip to content

Commit

Permalink
Merge branch 'main' into pr/2240
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Sep 12, 2023
2 parents abb0a79 + 02793cc commit 92ed141
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 64 deletions.
2 changes: 1 addition & 1 deletion src/packages/PkgCompat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ _stdlibs() = try
catch e
@warn "Pkg compat: failed to load standard libraries." exception=(e,catch_backtrace())

String["CRC32c", "Future", "Sockets", "MbedTLS_jll", "Random", "ArgTools", "libLLVM_jll", "GMP_jll", "Pkg", "Serialization", "LibSSH2_jll", "SHA", "OpenBLAS_jll", "REPL", "LibUV_jll", "nghttp2_jll", "Unicode", "Profile", "SparseArrays", "LazyArtifacts", "CompilerSupportLibraries_jll", "Base64", "Artifacts", "PCRE2_jll", "Printf", "p7zip_jll", "UUIDs", "Markdown", "TOML", "OpenLibm_jll", "Test", "MPFR_jll", "Mmap", "SuiteSparse", "LibGit2", "LinearAlgebra", "Logging", "NetworkOptions", "LibGit2_jll", "LibOSXUnwind_jll", "Dates", "LibUnwind_jll", "Libdl", "LibCURL_jll", "dSFMT_jll", "Distributed", "InteractiveUtils", "Downloads", "SharedArrays", "SuiteSparse_jll", "LibCURL", "Statistics", "Zlib_jll", "FileWatching", "DelimitedFiles", "Tar", "MozillaCACerts_jll"]
String["ArgTools", "Artifacts", "Base64", "CRC32c", "CompilerSupportLibraries_jll", "Dates", "DelimitedFiles", "Distributed", "Downloads", "FileWatching", "Future", "GMP_jll", "InteractiveUtils", "LLD_jll", "LLVMLibUnwind_jll", "LazyArtifacts", "LibCURL", "LibCURL_jll", "LibGit2", "LibGit2_jll", "LibOSXUnwind_jll", "LibSSH2_jll", "LibUV_jll", "LibUnwind_jll", "Libdl", "LinearAlgebra", "Logging", "MPFR_jll", "Markdown", "MbedTLS_jll", "Mmap", "MozillaCACerts_jll", "NetworkOptions", "OpenBLAS_jll", "OpenLibm_jll", "PCRE2_jll", "Pkg", "Printf", "Profile", "REPL", "Random", "SHA", "Serialization", "SharedArrays", "Sockets", "SparseArrays", "Statistics", "SuiteSparse", "SuiteSparse_jll", "TOML", "Tar", "Test", "UUIDs", "Unicode", "Zlib_jll", "dSFMT_jll", "libLLVM_jll", "libblastrampoline_jll", "nghttp2_jll", "p7zip_jll"]
end

# ⚠️ Internal API with fallback
Expand Down
36 changes: 13 additions & 23 deletions src/webserver/WebServer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@ function open_in_default_browser(url::AbstractString)::Bool
end
end

isurl(s::String) = startswith(s, "http://") || startswith(s, "https://")

function swallow_exception(f, exception_type::Type{T}) where {T}
try
f()
Expand Down Expand Up @@ -86,18 +84,6 @@ function run(port::Integer; kwargs...)
"
end

# open notebook(s) on startup

open_notebook!(session::ServerSession, notebook::Nothing) = Nothing

open_notebook!(session::ServerSession, notebook::AbstractString) = SessionActions.open(session, notebook)

function open_notebook!(session::ServerSession, notebook::AbstractVector{<:AbstractString})
for nb in notebook
SessionActions.open(session, nb)
end
end


const is_first_run = Ref(true)

Expand Down Expand Up @@ -136,8 +122,14 @@ function run(session::ServerSession)
store_session_middleware = create_session_context_middleware(session)
app = pluto_router |> auth_middleware |> store_session_middleware

notebook_at_startup = session.options.server.notebook
open_notebook!(session, notebook_at_startup)
let n = session.options.server.notebook
SessionActions.open.((session,),
n === nothing ? [] :
n isa AbstractString ? [n] :
n;
run_async=true,
)
end

host = session.options.server.host
hostIP = parse(Sockets.IPAddr, host)
Expand Down Expand Up @@ -319,10 +311,6 @@ function run(session::ServerSession)
end
precompile(run, (ServerSession, HTTP.Handlers.Router{Symbol("##001")}))

get_favorite_notebook(notebook::Nothing) = nothing
get_favorite_notebook(notebook::String) = notebook
get_favorite_notebook(notebook::AbstractVector) = first(notebook)

function pretty_address(session::ServerSession, hostIP, port)
root = if session.options.server.root_url !== nothing
@assert endswith(session.options.server.root_url, "/")
Expand Down Expand Up @@ -352,10 +340,12 @@ function pretty_address(session::ServerSession, hostIP, port)
if session.options.security.require_secret_for_access
url_params["secret"] = session.secret
end
fav_notebook = get_favorite_notebook(session.options.server.notebook)
fav_notebook = let n = session.options.server.notebook
n isa AbstractVector ? (isempty(n) ? nothing : first(n)) : n
end
new_root = if fav_notebook !== nothing
key = isurl(fav_notebook) ? "url" : "path"
url_params[key] = string(fav_notebook)
# since this notebook already started running, this will get redicted to that session
url_params["path"] = string(fav_notebook)
root * "open"
else
root
Expand Down
41 changes: 1 addition & 40 deletions test/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -126,42 +126,6 @@ end
@async schedule(server_task, InterruptException(); error=true)
end

@testset "Open Notebooks at Startup" begin
port = 1338
host = "localhost"
local_url(suffix) = "http://$host:$port/$suffix"

urls = [
"https://raw.githubusercontent.com/fonsp/Pluto.jl/v0.12.16/sample/Basic.jl",
"https://gist.githubusercontent.com/fonsp/4e164a262a60fc4bdd638e124e629d64/raw/8ffe93c680e539056068456a62dea7bf6b8eb622/basic_pkg_notebook.jl",
]
nbnames = download.(urls)

server_running() = HTTP.get(local_url("favicon.ico")).status == 200 && HTTP.get(local_url("edit")).status == 200

# without notebook at startup
server_task = @async Pluto.run(port=port, launch_browser=false, require_secret_for_access=false, require_secret_for_open_links=false)
@test poll(5) do
server_running()
end
@async schedule(server_task, InterruptException(); error=true)

# with a single notebook at startup
server_task = @async Pluto.run(notebook=first(nbnames), port=port, launch_browser=false, require_secret_for_access=false, require_secret_for_open_links=false)
@test poll(5) do
server_running()
end
@async schedule(server_task, InterruptException(); error=true)

# with multiple notebooks at startup
server_task = @async Pluto.run(notebook=nbnames, port=port, launch_browser=false, require_secret_for_access=false, require_secret_for_open_links=false)
@test poll(5) do
server_running()
end
@async schedule(server_task, InterruptException(); error=true)

end

@testset "disable mimetype via workspace_custom_startup_expr" begin
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = true
Expand All @@ -183,7 +147,4 @@ end
Pluto.WorkspaceManager.unmake_workspace((🍭, nb))
end

# TODO are the processes closed properly?
# TODO we reuse the same port without awaiting the shutdown of the previous server

end # testset
end

0 comments on commit 92ed141

Please sign in to comment.