Skip to content

Commit

Permalink
make notebook id available to notebook code
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Apr 26, 2021
1 parent df7f1e0 commit 72cfac4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function make_workspace((session, notebook)::SN; force_offline::Bool=false)::Wor
pid
end

Distributed.remotecall_eval(Main, [pid], :(PlutoRunner.notebook_id[] = $(notebook.notebook_id)))
log_channel = Core.eval(Main, quote
$(Distributed).RemoteChannel(() -> eval(:(Main.PlutoRunner.log_channel)), $pid)
end)
Expand Down
7 changes: 6 additions & 1 deletion src/runner/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import Distributed
import Base64
import FuzzyCompletions: Completion, ModuleCompletion, PropertyCompletion, FieldCompletion, completions, completion_text, score
import Base: show, istextmime
import UUIDs: UUID
import UUIDs: UUID, uuid4
import Logging

export @bind
Expand All @@ -41,6 +41,11 @@ ObjectDimPair = Tuple{ObjectID,Int64}
"The current workspace where your variables live. See [`move_vars`](@ref)."
current_module = Main

"""
`PlutoRunner.notebook_id[]` gives you the notebook ID used to identify a session.
"""
const notebook_id = Ref{UUID}(uuid4())

function set_current_module(newname)
# Revise.jl support
if isdefined(current_module, :Revise) &&
Expand Down
17 changes: 17 additions & 0 deletions test/Dynamic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,21 @@ end
@test occursin("square root", Pluto.PlutoRunner.doc_fetcher("Base.sqrt")[1])
@test occursin("No documentation found", Pluto.PlutoRunner.doc_fetcher("Base.findmeta")[1])
end

@testset "PlutoRunner API" begin
fakeclient = ClientSession(:fake, nothing)
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = true
🍭.connected_clients[fakeclient.id] = fakeclient

notebook = Notebook([
Cell("PlutoRunner.notebook_id[] |> Text"),
])
fakeclient.connected_notebook = notebook

update_save_run!(🍭, notebook, notebook.cells)
@test notebook.cells[1].output.body == notebook.notebook_id |> string

WorkspaceManager.unmake_workspace((🍭, notebook))
end
end
1 change: 1 addition & 0 deletions test/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import Pluto: update_save_run!, WorkspaceManager, ClientSession, ServerSession,
fakeclientA = ClientSession(:fakeA, nothing)
fakeclientB = ClientSession(:fakeB, nothing)
🍭 = ServerSession()
🍭.options.evaluation.workspace_use_distributed = true
🍭.connected_clients[fakeclientA.id] = fakeclientA
🍭.connected_clients[fakeclientB.id] = fakeclientB

Expand Down

0 comments on commit 72cfac4

Please sign in to comment.