Repository: PumasAI/QuartoNotebookRunner.jl (julia)

Issue:
Use `--project=@.` as default setting?
I think it would be convenient if QuartoNotebookRunner would use `--project=@.` as default setting for the worker processes. This would reduce the configuration (no `exeflags` needed) in many common cases and would match the behaviour of the default IJulia kernel: https://github.com/JuliaLang/IJulia.jl/blob/185533665803d5c0f9de6103d0c386422d9e1c6a/docs/src/manual/usage.md?plain=1#L18-L24

Pull request description:
With this PR, the setting `--project=@.` is used when executing a qmd file unless users specify explicitly a `JULIA_PROJECT` environment variable in `julia:env` or a `--project` flag in `julia:exeflags`.


Fixes #66.

Patch:
diff --git a/src/server.jl b/src/server.jl
index 6fefe967..2d09a09b 100644
--- a/src/server.jl
+++ b/src/server.jl
@@ -66,6 +66,10 @@ end
 function _exeflags_and_env(options)
     exeflags = map(String, options["format"]["metadata"]["julia"]["exeflags"])
     env = map(String, options["format"]["metadata"]["julia"]["env"])
+    # Use `--project=@.` if neither `JULIA_PROJECT=...` nor `--project=...` are specified
+    if !any(startswith("JULIA_PROJECT="), env) && !any(startswith("--project="), exeflags)
+        push!(exeflags, "--project=@.")
+    end
     return exeflags, env
 end
 


Test patch:
diff --git a/test/examples/project/dir/project_default.qmd b/test/examples/project/dir/project_default.qmd
new file mode 100644
index 00000000..acb2b6a4
--- /dev/null
+++ b/test/examples/project/dir/project_default.qmd
@@ -0,0 +1,25 @@
+---
+title: Project
+---
+
+Non-global project environment.
+
+```{julia}
+@isdefined(Example)
+```
+
+```{julia}
+Pkg.instantiate()
+```
+
+```{julia}
+Pkg.status()
+```
+
+```{julia}
+using Example
+```
+
+```{julia}
+isa(Example, Module)
+```
\ No newline at end of file
diff --git a/test/examples/project/project_default.qmd b/test/examples/project/project_default.qmd
new file mode 100644
index 00000000..acb2b6a4
--- /dev/null
+++ b/test/examples/project/project_default.qmd
@@ -0,0 +1,25 @@
+---
+title: Project
+---
+
+Non-global project environment.
+
+```{julia}
+@isdefined(Example)
+```
+
+```{julia}
+Pkg.instantiate()
+```
+
+```{julia}
+Pkg.status()
+```
+
+```{julia}
+using Example
+```
+
+```{julia}
+isa(Example, Module)
+```
\ No newline at end of file
diff --git a/test/examples/project_env.qmd b/test/examples/project_env.qmd
new file mode 100644
index 00000000..213cb6ea
--- /dev/null
+++ b/test/examples/project_env.qmd
@@ -0,0 +1,27 @@
+---
+title: Project
+julia:
+    env: ["JULIA_PROJECT=project"]
+---
+
+Non-global project environment.
+
+```{julia}
+@isdefined(Example)
+```
+
+```{julia}
+Pkg.instantiate()
+```
+
+```{julia}
+Pkg.status()
+```
+
+```{julia}
+using Example
+```
+
+```{julia}
+isa(Example, Module)
+```
\ No newline at end of file
diff --git a/test/testsets/project_example.jl b/test/testsets/project_example.jl
new file mode 100644
index 00000000..f622ec55
--- /dev/null
+++ b/test/testsets/project_example.jl
@@ -0,0 +1,37 @@
+include("../utilities/prelude.jl")
+
+for file in (
+    "project_env.qmd",
+    "project_exeflags.qmd",
+    "project/project_default.qmd",
+    "project/dir/project_default.qmd",
+)
+    test_example(joinpath(@__DIR__, "../examples", file)) do json
+        cells = json["cells"]
+
+        cell = cells[1]
+        @test cell["cell_type"] == "markdown"
+        @test any(line -> contains(line, "Non-global project environment."), cell["source"])
+
+        cell = cells[2]
+        @test cell["cell_type"] == "code"
+        @test cell["outputs"][1]["output_type"] == "execute_result"
+        @test cell["outputs"][1]["data"]["text/plain"] == "false"
+
+        cell = cells[6]
+        @test cell["cell_type"] == "code"
+        @test cell["outputs"][1]["output_type"] == "stream"
+        @test cell["outputs"][1]["name"] == "stdout"
+        @test contains(cell["outputs"][1]["text"], joinpath("examples", "project"))
+        @test contains(cell["outputs"][1]["text"], "[7876af07] Example")
+
+        cell = cells[8]
+        @test cell["cell_type"] == "code"
+        @test isempty(cell["outputs"])
+
+        cell = cells[10]
+        @test cell["cell_type"] == "code"
+        @test cell["outputs"][1]["output_type"] == "execute_result"
+        @test cell["outputs"][1]["data"]["text/plain"] == "true"
+    end
+end
diff --git a/test/testsets/project_exeflags.jl b/test/testsets/project_exeflags.jl
deleted file mode 100644
index 8aeb0dbe..00000000
--- a/test/testsets/project_exeflags.jl
+++ /dev/null
@@ -1,30 +0,0 @@
-include("../utilities/prelude.jl")
-
-test_example(joinpath(@__DIR__, "../examples/project_exeflags.qmd")) do json
-    cells = json["cells"]
-
-    cell = cells[1]
-    @test cell["cell_type"] == "markdown"
-    @test any(line -> contains(line, "Non-global project environment."), cell["source"])
-
-    cell = cells[2]
-    @test cell["cell_type"] == "code"
-    @test cell["outputs"][1]["output_type"] == "execute_result"
-    @test cell["outputs"][1]["data"]["text/plain"] == "false"
-
-    cell = cells[6]
-    @test cell["cell_type"] == "code"
-    @test cell["outputs"][1]["output_type"] == "stream"
-    @test cell["outputs"][1]["name"] == "stdout"
-    @test contains(cell["outputs"][1]["text"], joinpath("examples", "project"))
-    @test contains(cell["outputs"][1]["text"], "[7876af07] Example")
-
-    cell = cells[8]
-    @test cell["cell_type"] == "code"
-    @test isempty(cell["outputs"])
-
-    cell = cells[10]
-    @test cell["cell_type"] == "code"
-    @test cell["outputs"][1]["output_type"] == "execute_result"
-    @test cell["outputs"][1]["data"]["text/plain"] == "true"
-end