Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions src/QuartoNotebookWorker/src/refresh.jl
Original file line number Diff line number Diff line change
@@ -1,9 +1,31 @@
function refresh!(path, original_options, options = original_options)
# Current directory should always start out as the directory of the
# notebook file, which is not necessarily right initially if the parent
# process was started from a different directory to the notebook.
cd(dirname(path))
task_local_storage()[:SOURCE_PATH] = path

# We check the `execute-dir` key in the options,
if haskey(options, "project") && haskey(options["project"], "execute-dir")
ed = options["project"]["execute-dir"]
if ed == "file"
cd(dirname(path))
elseif ed == "project"
# TODO: this doesn't seem right. How does one get the root path of the project here?
# Maybe piggyback on `options` with some ridiculous identifier?
# We can't rely on `pwd`, because the notebook can change that.
if isfile(NotebookState.PROJECT[])
cd(dirname(NotebookState.PROJECT[]))
elseif isdir(NotebookState.PROJECT[])
cd(NotebookState.PROJECT[])
else
@warn "Project path not found: $(NotebookState.PROJECT[])"
end
else
error("Quarto only accepts `file` or `project` as arguments to `execute-dir`, got `$ed`.")
end
else
# Current directory should always start out as the directory of the
# notebook file, which is not necessarily right initially if the parent
# process was started from a different directory to the notebook.
cd(dirname(path))
end

# Reset back to the original project environment if it happens to
# have changed during cell evaluation.
Expand Down
7 changes: 7 additions & 0 deletions src/server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
julia_default = get(file_frontmatter, "julia", nothing)

params_default = get(file_frontmatter, "params", Dict{String,Any}())
project_default = get(file_frontmatter, "project", Dict{String,Any}())

if isempty(options)
return _options_template(;
Expand All @@ -441,6 +442,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
daemon = daemon_default,
params = params_default,
cache = cache_default,
project = project_default,
)
else
format = get(D, options, "format")
Expand Down Expand Up @@ -469,6 +471,8 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
cli_params = get(options, "params", Dict())
params_merged = _recursive_merge(params_default, params, cli_params)

project = get(metadata, "project", Dict())

return _options_template(;
fig_width,
fig_height,
Expand All @@ -481,6 +485,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
daemon,
params = params_merged,
cache,
project,
)
end
end
Expand All @@ -497,6 +502,7 @@ function _options_template(;
daemon,
params,
cache,
project,
)
D = Dict{String,Any}
return D(
Expand All @@ -515,6 +521,7 @@ function _options_template(;
"metadata" => D("julia" => julia),
),
"params" => D(params),
"project" => D(project),
)
end

Expand Down