Skip to content

Commit b14385b

Browse files
committed
Allow using a custom env for loading QuartoNotebookRunner
1 parent 6bf47bf commit b14385b

File tree

2 files changed

+42
-4
lines changed

2 files changed

+42
-4
lines changed

src/execute/julia.ts

Lines changed: 39 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,40 @@ async function startOrReuseJuliaServer(
239239
`Transport file ${transportFile} doesn't exist`,
240240
);
241241
info("Starting julia control server process. This might take a while...");
242-
await ensureQuartoNotebookRunnerEnvironment(options);
242+
243+
let juliaProject = Deno.env.get("QUARTO_JULIA_PROJECT");
244+
245+
if (juliaProject === undefined) {
246+
await ensureQuartoNotebookRunnerEnvironment(options);
247+
juliaProject = juliaRuntimeDir();
248+
} else {
249+
trace(
250+
options,
251+
`Custom julia project set via QUARTO_JULIA_PROJECT="${juliaProject}". Checking if QuartoNotebookRunner can be loaded.`,
252+
);
253+
const qnrTestCommand = new Deno.Command(options.julia_cmd, {
254+
args: [
255+
"--startup-file=no",
256+
`--project=${juliaProject}`,
257+
"-e",
258+
"using QuartoNotebookRunner",
259+
],
260+
env: {
261+
"JULIA_LOAD_PATH": "@:@stdlib", // ignore the main env
262+
},
263+
});
264+
const qnrTestProc = qnrTestCommand.spawn();
265+
const result = await qnrTestProc.output();
266+
if (!result.success) {
267+
throw Error(
268+
`Executing \`using QuartoNotebookRunner\` failed with QUARTO_JULIA_PROJECT="${juliaProject}". Ensure that this project exists, has QuartoNotebookRunner installed and is instantiated correctly.`,
269+
);
270+
}
271+
trace(
272+
options,
273+
`QuartoNotebookRunner could be loaded successfully.`,
274+
);
275+
}
243276

244277
// We need to spawn the julia server in its own process that can outlive quarto.
245278
// Apparently, `run(detach(cmd))` in julia does not do that reliably on Windows,
@@ -260,7 +293,7 @@ async function startOrReuseJuliaServer(
260293
// string array argument list, each element but the last must have a "," element after
261294
"--startup-file=no",
262295
",",
263-
`--project=${juliaRuntimeDir()}`,
296+
`--project=${juliaProject}`,
264297
",",
265298
resourcePath("julia/quartonotebookrunner.jl"),
266299
",",
@@ -269,6 +302,9 @@ async function startOrReuseJuliaServer(
269302
"-WindowStyle",
270303
"Hidden",
271304
],
305+
env: {
306+
"JULIA_LOAD_PATH": "@:@stdlib", // ignore the main env
307+
},
272308
},
273309
);
274310
trace(
@@ -285,7 +321,7 @@ async function startOrReuseJuliaServer(
285321
"--startup-file=no",
286322
resourcePath("julia/start_quartonotebookrunner_detached.jl"),
287323
options.julia_cmd,
288-
juliaRuntimeDir(),
324+
juliaProject,
289325
resourcePath("julia/quartonotebookrunner.jl"),
290326
transportFile,
291327
],

src/resources/julia/start_quartonotebookrunner_detached.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,7 @@ if length(ARGS) > 4
99
error("Too many arguments")
1010
end
1111

12+
env = copy(ENV)
13+
env["JULIA_LOAD_PATH"] = "@:@stdlib" # ignore the main env
1214
cmd = `$julia_bin --startup-file=no --project=$project $julia_file $transport_file`
13-
run(detach(cmd), wait = false)
15+
run(detach(setenv(cmd, env)), wait = false)

0 commit comments

Comments
 (0)