From e1bd21ca76c4883c61ca6eb4a8aa7bd335f005c8 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Tue, 12 Sep 2023 22:27:43 +0200 Subject: [PATCH 1/2] Cleanup notebook config code and remove janky test --- src/webserver/WebServer.jl | 36 ++++++++++++--------------------- test/Configuration.jl | 41 +------------------------------------- 2 files changed, 14 insertions(+), 63 deletions(-) diff --git a/src/webserver/WebServer.jl b/src/webserver/WebServer.jl index fbdff63f5a..a016fcadad 100644 --- a/src/webserver/WebServer.jl +++ b/src/webserver/WebServer.jl @@ -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() @@ -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) @@ -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) @@ -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, "/") @@ -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 diff --git a/test/Configuration.jl b/test/Configuration.jl index 0b6b131618..0507f688ea 100644 --- a/test/Configuration.jl +++ b/test/Configuration.jl @@ -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, workspace_use_distributed=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, workspace_use_distributed=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, workspace_use_distributed=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 @@ -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 From 02793cce359ae80f775c669cec095022002d6c77 Mon Sep 17 00:00:00 2001 From: Fons van der Plas Date: Tue, 12 Sep 2023 22:27:57 +0200 Subject: [PATCH 2/2] update fallback stdlibs list --- src/packages/PkgCompat.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/packages/PkgCompat.jl b/src/packages/PkgCompat.jl index 250b275359..f0e857fc00 100644 --- a/src/packages/PkgCompat.jl +++ b/src/packages/PkgCompat.jl @@ -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