Skip to content

Commit

Permalink
workspace_custom_startup_expr as String
Browse files Browse the repository at this point in the history
  • Loading branch information
fonsp committed Sep 20, 2023
1 parent 871517c commit 3e0ea0d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -156,15 +156,25 @@ These options are not intended to be changed during normal use.
- `workspace_use_distributed_stdlib::Bool? = $WORKSPACE_USE_DISTRIBUTED_STDLIB_DEFAULT` Should we use the Distributed stdlib to run processes? Distributed will be replaced by Malt.jl, you can use this option to already get the old behaviour. `nothing` means: determine automatically (which is currently the same as `true`).
- `lazy_workspace_creation::Bool = $LAZY_WORKSPACE_CREATION_DEFAULT`
- `capture_stdout::Bool = $CAPTURE_STDOUT_DEFAULT`
- `workspace_custom_startup_expr::Union{Nothing,Expr} = $WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT` An expression to be evaluated in the workspace process before running notebook code.
- `workspace_custom_startup_expr::Union{Nothing,String} = $WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT` An expression to be evaluated in the workspace process before running notebook code.
"""
@option mutable struct EvaluationOptions
run_notebook_on_load::Bool = RUN_NOTEBOOK_ON_LOAD_DEFAULT
workspace_use_distributed::Bool = WORKSPACE_USE_DISTRIBUTED_DEFAULT
workspace_use_distributed_stdlib::Union{Bool,Nothing} = WORKSPACE_USE_DISTRIBUTED_STDLIB_DEFAULT
lazy_workspace_creation::Bool = LAZY_WORKSPACE_CREATION_DEFAULT
capture_stdout::Bool = CAPTURE_STDOUT_DEFAULT
workspace_custom_startup_expr::Union{Nothing,Expr} = WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT
workspace_custom_startup_expr::Union{Nothing,String} = WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT
end

# TODO: deprecated, remove me in the next breaking release
function Base.setproperty!(x::EvaluationOptions, property::Symbol, val)
if property === :workspace_custom_startup_expr && val isa Expr
@warn "Deprecated: workspace_custom_startup_expr should be a String, not an Expr."
setfield!(x, property, string(val))
else
setfield!(x, property, val)
end
end

const COMPILE_DEFAULT = nothing
Expand Down Expand Up @@ -298,7 +308,7 @@ function from_flat_kwargs(;
workspace_use_distributed_stdlib::Union{Bool,Nothing} = WORKSPACE_USE_DISTRIBUTED_STDLIB_DEFAULT,
lazy_workspace_creation::Bool = LAZY_WORKSPACE_CREATION_DEFAULT,
capture_stdout::Bool = CAPTURE_STDOUT_DEFAULT,
workspace_custom_startup_expr::Union{Nothing,Expr} = WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT,
workspace_custom_startup_expr::Union{Nothing,String} = WORKSPACE_CUSTOM_STARTUP_EXPR_DEFAULT,

compile::Union{Nothing,String} = COMPILE_DEFAULT,
pkgimages::Union{Nothing,String} = PKGIMAGES_DEFAULT,
Expand Down
4 changes: 3 additions & 1 deletion src/evaluation/WorkspaceManager.jl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ function make_workspace((session, notebook)::SN; is_offline_renderer::Bool=false
Status.report_business_planned!(init_status, Symbol(3))
Status.report_business_planned!(init_status, Symbol(4))

Malt.remote_eval_wait(worker, session.options.evaluation.workspace_custom_startup_expr)
let s = session.options.evaluation.workspace_custom_startup_expr
s === nothing || Malt.remote_eval_wait(worker, Meta.parse(s))
end

Malt.remote_eval_wait(worker, quote
PlutoRunner.notebook_id[] = $(notebook.notebook_id)
Expand Down
9 changes: 9 additions & 0 deletions test/Configuration.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,15 @@ end
PlutoRunner.is_mime_enabled(m::MIME"application/vnd.pluto.tree+object") = false
end

# backwards compat: setting the value to an Expr should still work
@test 🍭.options.evaluation.workspace_custom_startup_expr isa String
@test occursin("PlutoRunner.is_mime_enabled", 🍭.options.evaluation.workspace_custom_startup_expr)

# normally you set it to a String
🍭.options.evaluation.workspace_custom_startup_expr = """
PlutoRunner.is_mime_enabled(m::MIME"application/vnd.pluto.tree+object") = false
"""

nb = Pluto.Notebook([
Pluto.Cell("x = [1, 2]")
Pluto.Cell("struct Foo; x; end")
Expand Down

0 comments on commit 3e0ea0d

Please sign in to comment.