diff --git a/src/QuartoNotebookWorker/src/refresh.jl b/src/QuartoNotebookWorker/src/refresh.jl index ca6154e..1e7b28b 100644 --- a/src/QuartoNotebookWorker/src/refresh.jl +++ b/src/QuartoNotebookWorker/src/refresh.jl @@ -1,8 +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)) + # 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 == "directory" + 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[]) + elseif isdir(ed) + cd(ed) + else + @warn "Project path not found: $(NotebookState.PROJECT[])" + end + else + cd(abspath(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. diff --git a/src/server.jl b/src/server.jl index f881d75..23ee60b 100644 --- a/src/server.jl +++ b/src/server.jl @@ -178,6 +178,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(; @@ -191,6 +192,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict) julia = julia_default, daemon = daemon_default, params = params_default, + project = project_default, ) else format = get(D, options, "format") @@ -218,6 +220,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, @@ -229,6 +233,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict) julia = julia_merged, daemon, params = params_merged, + project, ) end end @@ -244,6 +249,7 @@ function _options_template(; julia, daemon, params, + project, ) D = Dict{String,Any} return D( @@ -261,6 +267,7 @@ function _options_template(; "metadata" => D("julia" => julia), ), "params" => D(params), + "project" => D(project), ) end