@@ -24,13 +24,18 @@ mutable struct File
2424 options = _parsed_options (options)
2525 _, _, file_frontmatter = raw_text_chunks (path)
2626 merged_options = _extract_relevant_options (file_frontmatter, options)
27- exeflags, env = _exeflags_and_env (merged_options)
27+ exeflags, env, quarto_env = _exeflags_and_env (merged_options)
2828 timeout = _extract_timeout (merged_options)
2929
30-
3130 exe, _exeflags = _julia_exe (exeflags)
32- worker =
33- cd (() -> Malt. Worker (; exe, exeflags = _exeflags, env), dirname (path))
31+ worker = cd (
32+ () -> Malt. Worker (;
33+ exe,
34+ exeflags = _exeflags,
35+ env = vcat (env, quarto_env),
36+ ),
37+ dirname (path),
38+ )
3439 file = new (
3540 worker,
3641 path,
@@ -104,7 +109,7 @@ function _julia_exe(exeflags)
104109end
105110
106111function _extract_timeout (merged_options)
107- daemon = merged_options[" format" ][" execute" ][" daemon" ]
112+ daemon = something ( merged_options[" format" ][" execute" ][" daemon" ], true )
108113 if daemon === true
109114 300.0 # match quarto's default timeout of 300 seconds
110115 elseif daemon === false
@@ -149,6 +154,13 @@ function _exeflags_and_env(options)
149154 # if exeflags already contains '--color=no', the 'no' will prevail
150155 pushfirst! (exeflags, " --color=yes" )
151156
157+ # Several QUARTO_* environment variables are passed to the worker process
158+ # via the `env` field rather than via real environment variables. Capture
159+ # these and pass them to the worker process separate from `env` since that
160+ # is used by the worker status printout and we don't want these extra ones
161+ # that the user has not set themselves to show up there.
162+ quarto_env = Base. byteenv (options[" env" ])
163+
152164 # Ensure that coverage settings are passed to the worker so that worker
153165 # code is tracked correctly during tests.
154166 # Based on https://github.com/JuliaLang/julia/blob/eed18bdf706b7aab15b12f3ba0588e8fafcd4930/base/util.jl#L216-L229.
@@ -171,7 +183,7 @@ function _exeflags_and_env(options)
171183 end
172184 end
173185
174- return exeflags, env
186+ return exeflags, env, quarto_env
175187end
176188
177189struct Server
@@ -205,12 +217,14 @@ function init!(file::File, options::Dict)
205217end
206218
207219function refresh! (file:: File , options:: Dict )
208- exeflags, env = _exeflags_and_env (options)
220+ exeflags, env, quarto_env = _exeflags_and_env (options)
209221 if exeflags != file. exeflags || env != file. env || ! Malt. isrunning (file. worker) # the worker might have been killed on another task
210222 Malt. stop (file. worker)
211223 exe, _exeflags = _julia_exe (exeflags)
212- file. worker =
213- cd (() -> Malt. Worker (; exe, exeflags = _exeflags, env), dirname (file. path))
224+ file. worker = cd (
225+ () -> Malt. Worker (; exe, exeflags = _exeflags, env = vcat (env, quarto_env)),
226+ dirname (file. path),
227+ )
214228 file. exe = exe
215229 file. exeflags = exeflags
216230 file. env = env
@@ -441,9 +455,11 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
441455 daemon = daemon_default,
442456 params = params_default,
443457 cache = cache_default,
458+ env = Dict {String,Any} (),
444459 )
445460 else
446461 format = get (D, options, " format" )
462+ env = get (D, options, " env" )
447463 execute = get (D, format, " execute" )
448464 fig_width = get (execute, " fig-width" , fig_width_default)
449465 fig_height = get (execute, " fig-height" , fig_height_default)
@@ -481,6 +497,7 @@ function _extract_relevant_options(file_frontmatter::Dict, options::Dict)
481497 daemon,
482498 params = params_merged,
483499 cache,
500+ env,
484501 )
485502 end
486503end
@@ -497,6 +514,7 @@ function _options_template(;
497514 daemon,
498515 params,
499516 cache,
517+ env,
500518)
501519 D = Dict{String,Any}
502520 return D (
@@ -515,6 +533,7 @@ function _options_template(;
515533 " metadata" => D (" julia" => julia),
516534 ),
517535 " params" => D (params),
536+ " env" => env,
518537 )
519538end
520539
@@ -1466,7 +1485,7 @@ function run!(
14661485 chunk_callback = (i, n, c) -> nothing ,
14671486)
14681487 try
1469- borrow_file! (server, path; optionally_create = true ) do file
1488+ borrow_file! (server, path; options, optionally_create = true ) do file
14701489 if file. timeout_timer != = nothing
14711490 close (file. timeout_timer)
14721491 file. timeout_timer = nothing
@@ -1606,7 +1625,7 @@ function borrow_file!(
16061625 get (server. workers, apath, nothing )
16071626 end
16081627 if file != = current_file
1609- return borrow_file! (f, server, apath; optionally_create)
1628+ return borrow_file! (f, server, apath; options, optionally_create)
16101629 else
16111630 return f (file)
16121631 end
0 commit comments