From e203401500a3ddfc5bda4d74a76142688be35f27 Mon Sep 17 00:00:00 2001 From: MichaelHatherly Date: Fri, 7 Jun 2024 14:48:31 +0100 Subject: [PATCH] Fix #142, `InteractiveUtils` should be imported by default --- Project.toml | 2 ++ src/QuartoNotebookRunner.jl | 1 + src/QuartoNotebookWorker/Project.toml | 1 + src/QuartoNotebookWorker/src/NotebookState.jl | 6 +++++- src/QuartoNotebookWorker/src/QuartoNotebookWorker.jl | 1 + test/examples/cell_types.jl | 3 +++ test/examples/cell_types.qmd | 4 ++++ test/testsets/cell_types.jl | 10 +++++++++- test/testsets/socket_server/socket_server.jl | 2 +- 9 files changed, 27 insertions(+), 3 deletions(-) diff --git a/Project.toml b/Project.toml index 8f6ebec..8627996 100644 --- a/Project.toml +++ b/Project.toml @@ -8,6 +8,7 @@ Base64 = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" CommonMark = "a80b9123-70ca-4bc0-993e-6e3bcb318db6" Compat = "34da2185-b29b-5c13-b0c7-acf172513d20" IOCapture = "b5f81e59-6552-4d32-b1f0-c071b021bf89" +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" IterTools = "c8e1da08-722c-5040-9ed9-7db0dc04731e" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" @@ -30,6 +31,7 @@ Base64 = "1.6" CommonMark = "0.8" Compat = "4" IOCapture = "0.2" +InteractiveUtils = "1.6" IterTools = "1" JSON3 = "1" Logging = "1.6" diff --git a/src/QuartoNotebookRunner.jl b/src/QuartoNotebookRunner.jl index a25c13b..d0328b3 100644 --- a/src/QuartoNotebookRunner.jl +++ b/src/QuartoNotebookRunner.jl @@ -22,6 +22,7 @@ import Base64 import CommonMark import Compat import IOCapture +import InteractiveUtils import IterTools import JSON3 import Logging diff --git a/src/QuartoNotebookWorker/Project.toml b/src/QuartoNotebookWorker/Project.toml index 425209a..cf0f4c4 100644 --- a/src/QuartoNotebookWorker/Project.toml +++ b/src/QuartoNotebookWorker/Project.toml @@ -4,6 +4,7 @@ authors = ["MichaelHatherly "] version = "0.1.0" [deps] +InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" diff --git a/src/QuartoNotebookWorker/src/NotebookState.jl b/src/QuartoNotebookWorker/src/NotebookState.jl index ede0b4f..c405228 100644 --- a/src/QuartoNotebookWorker/src/NotebookState.jl +++ b/src/QuartoNotebookWorker/src/NotebookState.jl @@ -39,7 +39,11 @@ function define_notebook_module!(root = Main) # Add some default imports. Rather than directly using `import` we just # `const` them directly from the `Function` objects themselves. imports = quote - const Pkg = $(Pkg) + # We can import `QuartoNotebookWorker` since we have pushed it onto the + # end of `LOAD_PATH`. + import QuartoNotebookWorker.Pkg + using QuartoNotebookWorker.InteractiveUtils + const ojs_define = $(QuartoNotebookWorker.ojs_define) const include = $(QuartoNotebookWorker.NotebookInclude.include) const eval = $(QuartoNotebookWorker.NotebookInclude.eval) diff --git a/src/QuartoNotebookWorker/src/QuartoNotebookWorker.jl b/src/QuartoNotebookWorker/src/QuartoNotebookWorker.jl index 395e208..716d378 100644 --- a/src/QuartoNotebookWorker/src/QuartoNotebookWorker.jl +++ b/src/QuartoNotebookWorker/src/QuartoNotebookWorker.jl @@ -79,6 +79,7 @@ end # Imports. +import InteractiveUtils import Pkg import REPL diff --git a/test/examples/cell_types.jl b/test/examples/cell_types.jl index 1770217..017951b 100644 --- a/test/examples/cell_types.jl +++ b/test/examples/cell_types.jl @@ -21,3 +21,6 @@ println(1) # %% div(1, 0) + +# %% +versioninfo() diff --git a/test/examples/cell_types.qmd b/test/examples/cell_types.qmd index e83e7ea..32012f6 100644 --- a/test/examples/cell_types.qmd +++ b/test/examples/cell_types.qmd @@ -18,4 +18,8 @@ Errors: ```{julia} div(1, 0) +``` + +```{julia} +versioninfo() ``` \ No newline at end of file diff --git a/test/testsets/cell_types.jl b/test/testsets/cell_types.jl index 7facc84..3de6871 100644 --- a/test/testsets/cell_types.jl +++ b/test/testsets/cell_types.jl @@ -1,7 +1,7 @@ include("../utilities/prelude.jl") test_example(joinpath(@__DIR__, "../examples/cell_types.qmd")) do json - @test length(json["cells"]) == 6 + @test length(json["cells"]) == 8 cell = json["cells"][1] @test cell["cell_type"] == "markdown" @@ -42,4 +42,12 @@ test_example(joinpath(@__DIR__, "../examples/cell_types.qmd")) do json @test contains(traceback, "div") @test count("top-level scope", traceback) == 1 @test count(r"cell_types\.(qmd|jl):", traceback) == 1 + + cell = json["cells"][8] + outputs = cell["outputs"] + @test length(outputs) == 1 + output = outputs[1] + @test output["output_type"] == "stream" + @test output["name"] == "stdout" + @test startswith(output["text"], "Julia Version ") end diff --git a/test/testsets/socket_server/socket_server.jl b/test/testsets/socket_server/socket_server.jl index 5d8a3ab..2fc7e43 100644 --- a/test/testsets/socket_server/socket_server.jl +++ b/test/testsets/socket_server/socket_server.jl @@ -16,7 +16,7 @@ include("../../utilities/prelude.jl") @test d1 == false d2 = json(`$node $client $(server.port) $(server.key) run $(cell_types)`) - @test length(d2["notebook"]["cells"]) == 6 + @test length(d2["notebook"]["cells"]) == 8 d3 = json(`$node $client $(server.port) $(server.key) isopen $(cell_types)`) @test d3 == true