Skip to content

Commit 36ccd88

Browse files
authored
Merge pull request #9373 from PumasAI/jk/custom-julia-project
Allow using a custom env for loading QuartoNotebookRunner
2 parents 83f7e57 + 1a52779 commit 36ccd88

File tree

2 files changed

+48
-4
lines changed

2 files changed

+48
-4
lines changed

src/execute/julia.ts

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,43 @@ 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+
// ignore the main env
262+
"JULIA_LOAD_PATH": Deno.build.os === "windows"
263+
? "@;@stdlib"
264+
: "@:@stdlib",
265+
},
266+
});
267+
const qnrTestProc = qnrTestCommand.spawn();
268+
const result = await qnrTestProc.output();
269+
if (!result.success) {
270+
throw Error(
271+
`Executing \`using QuartoNotebookRunner\` failed with QUARTO_JULIA_PROJECT="${juliaProject}". Ensure that this project exists, has QuartoNotebookRunner installed and is instantiated correctly.`,
272+
);
273+
}
274+
trace(
275+
options,
276+
`QuartoNotebookRunner could be loaded successfully.`,
277+
);
278+
}
243279

244280
// We need to spawn the julia server in its own process that can outlive quarto.
245281
// Apparently, `run(detach(cmd))` in julia does not do that reliably on Windows,
@@ -260,7 +296,7 @@ async function startOrReuseJuliaServer(
260296
// string array argument list, each element but the last must have a "," element after
261297
"--startup-file=no",
262298
",",
263-
`--project=${juliaRuntimeDir()}`,
299+
`--project=${juliaProject}`,
264300
",",
265301
resourcePath("julia/quartonotebookrunner.jl"),
266302
",",
@@ -269,6 +305,9 @@ async function startOrReuseJuliaServer(
269305
"-WindowStyle",
270306
"Hidden",
271307
],
308+
env: {
309+
"JULIA_LOAD_PATH": "@;@stdlib", // ignore the main env
310+
},
272311
},
273312
);
274313
trace(
@@ -285,10 +324,13 @@ async function startOrReuseJuliaServer(
285324
"--startup-file=no",
286325
resourcePath("julia/start_quartonotebookrunner_detached.jl"),
287326
options.julia_cmd,
288-
juliaRuntimeDir(),
327+
juliaProject,
289328
resourcePath("julia/quartonotebookrunner.jl"),
290329
transportFile,
291330
],
331+
env: {
332+
"JULIA_LOAD_PATH": "@:@stdlib", // ignore the main env
333+
},
292334
});
293335
trace(
294336
options,

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)