Skip to content

Commit

Permalink
less generic code
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Sep 17, 2024
1 parent ebf1f6e commit d6397f3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 19 deletions.
4 changes: 3 additions & 1 deletion src/runner/PlutoRunner/src/PlutoRunner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ include("./io/logging.jl")
include("./io/stdout.jl")
include("./precompile.jl")

__init__() = redirect_original_stderr(stderr)
function __init__()
original_stderr[] = stderr
end

end
15 changes: 0 additions & 15 deletions src/runner/PlutoRunner/src/io/logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,6 @@ import Logging

const original_stderr = Ref{IO}()

function redirect_original_stderr(io)
original_stderr[] = io
return nothing
end

function redirect_original_stderr(f::Function, io)
old_stderr = original_stderr[]
redirect_original_stderr(io)
try
return f()
finally
redirect_original_stderr(old_stderr)
end
end

const old_logger = Ref{Union{Logging.AbstractLogger,Nothing}}(nothing)

struct PlutoCellLogger <: Logging.AbstractLogger
Expand Down
9 changes: 6 additions & 3 deletions test/Logging.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,14 @@ using Pluto.WorkspaceManager: poll
🍍.options.evaluation.workspace_use_distributed = false

io = IOBuffer()
PlutoRunner.redirect_original_stderr(io) do
update_run!(🍍, notebook, notebook.cells[27:29])
end
old_stderr = PlutoRunner.original_stderr[]
PlutoRunner.original_stderr[] = io

update_run!(🍍, notebook, notebook.cells[27:29])

msg = String(take!(io))
close(io)
PlutoRunner.original_stderr[] = old_stderr

@test notebook.cells[27] |> noerror
@test notebook.cells[28] |> noerror
Expand Down

0 comments on commit d6397f3

Please sign in to comment.