Skip to content

Commit

Permalink
Merge branch 'main' into banner2
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp authored Sep 13, 2023
2 parents 9b9a73a + b3205cb commit 6ee6231
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 89 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/Test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ on:
jobs:
test:
runs-on: ${{ matrix.os }}
timeout-minutes: 40
timeout-minutes: 50

strategy:
# Without setting this, a failing test cancels all others
Expand Down
66 changes: 43 additions & 23 deletions frontend/components/ExportBanner.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,23 @@ const Square = ({ fill }) => html`
</svg>
`

//@ts-ignore
window.enable_secret_pluto_recording = true
export const WarnForVisisblePasswords = () => {
if (
Array.from(document.querySelectorAll("bond")).some((bond_el) =>
Array.from(bond_el.querySelectorAll(`input[type="password"]`)).some((input) => {
// @ts-ignore
if (input?.value !== "") {
input.scrollIntoView()
return true
}
})
)
) {
alert(
"Warning: this notebook includes a password input with something typed in it. The contents of this password field will be included in the exported file in an unsafe way. \n\nClear the password field and export again to avoid this problem."
)
}
}

export const ExportBanner = ({ notebook_id, onClose, notebookfile_url, notebookexport_url, start_recording }) => {
// @ts-ignore
Expand All @@ -49,34 +64,39 @@ export const ExportBanner = ({ notebook_id, onClose, notebookfile_url, notebooke
<header><${Triangle} fill="#a270ba" /> Notebook file</header>
<section>Download a copy of the <b>.jl</b> script.</section>
</a>
<a href=${notebookexport_url} target="_blank" class="export_card" download="" onClick=${(e) => exportNotebook(e, 1)}>
<a
href=${notebookexport_url}
target="_blank"
class="export_card"
download=""
onClick=${(e) => {
WarnForVisisblePasswords()
exportNotebook(e, 1)
}}
>
<header><${Square} fill="#E86F51" /> Static HTML</header>
<section>An <b>.html</b> file for your web page, or to share online.</section>
</a>
<a href="#" class="export_card" onClick=${() => window.print()}>
<header><${Square} fill="#619b3d" /> PDF</header>
<section>A static <b>.pdf</b> file for print or email.</section>
</a>
${
//@ts-ignore
window.enable_secret_pluto_recording
? html`
<div class="export_title">record</div>
<a
href="#"
onClick=${(e) => {
start_recording()
onClose()
e.preventDefault()
}}
class="export_card"
>
<header><${Circle} fill="#E86F51" /> Record <em>(preview)</em></header>
<section>Capture the entire notebook, and any changes you make.</section>
</a>
`
: null
}
${html`
<div class="export_title">record</div>
<a
href="#"
onClick=${(e) => {
WarnForVisisblePasswords()
start_recording()
onClose()
e.preventDefault()
}}
class="export_card"
>
<header><${Circle} fill="#E86F51" /> Record <em>(preview)</em></header>
<section>Capture the entire notebook, and any changes you make.</section>
</a>
`}
<div class="export_small_btns">
<button
title="Edit frontmatter"
Expand Down
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, 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
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
6 changes: 5 additions & 1 deletion test/packages/Basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ import Distributed
WorkspaceManager.unmake_workspace((🍭, notebook))
end

@static if VERSION ≀ v"1.9"
@static if VERSION < v"1.10.0-0" # see https://github.com/fonsp/Pluto.jl/pull/2626#issuecomment-1671244510
@testset "File format -- Forwards compat" begin
# Using Distributed, we will create a new Julia process in which we install Pluto 0.14.7 (before PlutoPkg). We run the new notebook file on the old Pluto.
p = Distributed.addprocs(1) |> first
Expand Down Expand Up @@ -650,6 +650,8 @@ import Distributed
end

@testset "PlutoRunner Syntax Error" begin
🍭 = ServerSession()

notebook = Notebook([
Cell("1 +"),
Cell("PlutoRunner.throw_syntax_error"),
Expand All @@ -665,6 +667,8 @@ import Distributed
@test Pluto.is_just_text(notebook.topology, notebook.cells[1])
@test !Pluto.is_just_text(notebook.topology, notebook.cells[2]) # Not a syntax error form
@test Pluto.is_just_text(notebook.topology, notebook.cells[3])

WorkspaceManager.unmake_workspace((🍭, notebook))
end

@testset "Precompilation" begin
Expand Down

0 comments on commit 6ee6231

Please sign in to comment.