### Install PackageExtensionCompatDemo Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/PackageExtensionCompat/example/PackageExtensionCompatDemo/README.md Use Pkg.develop to install the demo package and Pkg.add to install the required Example package. ```julia using Pkg Pkg.develop("/path/to/PackageExtensionCompatDemo") Pkg.add("Example") ``` -------------------------------- ### Install QuartoNotebookRunner Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Install the package into an isolated named environment to avoid global environment conflicts. ```shell julia --project=@quarto -e 'import Pkg; Pkg.add("QuartoNotebookRunner")' ``` -------------------------------- ### Call hello_world with Example loaded Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/PackageExtensionCompat/example/PackageExtensionCompatDemo/README.md Loading the `Example` package before calling `hello_world()` allows the function to execute successfully. ```julia using Example hello_world() # "Hello, World" ``` -------------------------------- ### Call hello_world without Example loaded Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/PackageExtensionCompat/example/PackageExtensionCompatDemo/README.md Calling `hello_world()` before loading the `Example` package will result in an error. ```julia using PackageExtensionCompatDemo hello_world() # ERROR: ... ``` -------------------------------- ### Start Daemon Mode Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Starts the socket server for the QuartoNotebookRunner to interact via JSON API. ```julia julia --project=@quarto -e 'import QuartoNotebookRunner; QuartoNotebookRunner.serve(; port = 1234)' ``` -------------------------------- ### Start Socket Server Daemon with serve Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Starts a TCP socket server for notebook execution commands, enabling integration with external tools like the Quarto CLI. Messages must be HMAC-signed for security. Supports automatic port selection and timeouts. ```julia using QuartoNotebookRunner # Start socket server on a specific port socketserver = QuartoNotebookRunner.serve(; port = 1234, showprogress = true) # Start with automatic port selection and timeout socketserver = QuartoNotebookRunner.serve(; port = nothing, # Random available port timeout = 300.0, # Close after 5 minutes of inactivity showprogress = true ) # Access server details println("Server running on port: ", socketserver.port) println("Server key (for HMAC): ", socketserver.key) # Block until server is stopped wait(socketserver) ``` -------------------------------- ### Initialize Julia Environment Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Start a Julia session within the project environment. ```shell julia --project=@quarto ``` -------------------------------- ### Start Quarto preview with Revise Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/revise/README.md Use the justfile to launch a Quarto server with Revise enabled for the specified notebook file. ```shell $ just revise quarto preview filename.qmd ``` -------------------------------- ### Socket Server Run Command Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Example of a JSON message to execute a notebook via the socket server. ```json // Run command - execute a notebook { "type": "run", "content": { "file": "/absolute/path/to/notebook.qmd", "options": { "format": { "execute": { "fig-width": 8, "error": true } } } } } ``` -------------------------------- ### Start Interactive Worker Debugging Session Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Start an interactive REPL session within a worker process for debugging QuartoNotebookWorker functionality. Revise.jl, TestEnv, and Debugger are loaded if available. ```julia using QuartoNotebookRunner # Start an interactive debug session in a worker subprocess # Revise.jl, TestEnv, and Debugger are automatically loaded if available QuartoNotebookRunner.WorkerSetup.debug() # In the worker REPL: # julia> QuartoNotebookWorker. # Explore worker functionality # julia> # Edit src/QuartoNotebookWorker files - changes reflect via Revise # Use ctrl-d or exit() to return to main REPL ``` -------------------------------- ### Socket Server Daemon Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Methods for starting a TCP socket server to accept remote execution commands. ```APIDOC ## serve ### Description Starts a TCP socket server that accepts JSON commands for notebook execution. Messages require HMAC signing for security. ### Parameters - **port** (Int/Nothing) - Optional - Port to listen on. If nothing, selects a random port. - **timeout** (Float64) - Optional - Inactivity timeout in seconds. - **showprogress** (Bool) - Optional - Whether to show progress. ### Request Example ```julia socketserver = QuartoNotebookRunner.serve(; port = 1234, showprogress = true) ``` ``` -------------------------------- ### Usage of Replicate in QMD Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Examples of using the Replicate type within a Quarto document to generate dynamic cells. ```qmd ```{julia} using PackageName ``` Generate two cells that each output "Hello" as their returned value. ```{julia} Replicate("Hello", 2) ``` Next we generate three cells that each push the current `DateTime` to a shared `state` vector, print `"World"` to `stdout` and then return the entire `state` for rendering. The `echo: false` option is used to suppress the output of the original cell itself. ```{julia} #| echo: false import Dates let state = [] Replicate(3) do push!(state, Dates.now()) println("World") return state end end ``` ``` -------------------------------- ### Quarto Notebook YAML Frontmatter Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Example of YAML frontmatter in a Quarto notebook, configuring title, figure format, and Julia execution options. ```markdown --- title: "Data Analysis Report" fig-format: png fig-dpi: 150 julia: exeflags: ["--threads=4"] env: ["JULIA_NUM_THREADS=4"] execute: error: false cache: true params: alpha: 0.05 dataset: "training" --- ``` -------------------------------- ### Debug Worker Package Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Commands to load the worker package and start a debugging REPL session. ```julia julia> using QuartoNotebookRunner # Load the runner package. julia> QuartoNotebookRunner.WorkerSetup.debug() # Start a subprocess with the worker package loaded. ``` ```julia julia> QuartoNotebookWorker. # Access the worker package. ``` -------------------------------- ### Demo: Conditional Module Loading with @require Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md This example demonstrates how a module (Colors) is loaded only after another module (JSON) is used. It shows the dynamic loading behavior of Requires.jl. ```julia module Reqs using Requires function __init__() @require JSON="682c06a0-de6a-54ab-a142-c8b1cf79cde6" @eval using Colors end end ``` -------------------------------- ### Quarto Notebook Dynamic Cell Generation Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Example of using the `expand` function in a package extension to dynamically generate multiple cells from a single cell's result. ```julia # In your package extension file: ext/MyPackageQuartoNotebookWorkerExt.jl module MyPackageQuartoNotebookWorkerExt import MyPackage import QuartoNotebookWorker: Cell, expand # Define a type that expands into multiple cells struct ReportSections sections::Vector{NamedTuple} end function QuartoNotebookWorker.expand(r::ReportSections) return [ Cell( section.generator; # Function to generate content code = section.code, options = get(section, :options, Dict()) ) for section in r.sections ] end end # module # Usage in a notebook: # ```{julia} # using MyPackage # ReportSections([ # (generator = () -> plot(data1), code = "plot(data1)", options = Dict("fig-cap" => "Figure 1")), # (generator = () -> plot(data2), code = "plot(data2)", options = Dict("fig-cap" => "Figure 2")), # ]) # ``` ``` -------------------------------- ### Define Replicate type Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md The module definition for the Replicate type used in the expansion example. ```julia module PackageName export Replicate struct Replicate value n::Int end end ``` -------------------------------- ### One-Shot Notebook Rendering with render Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Provides a simple API for one-time notebook rendering. It automatically creates a temporary server, runs the notebook, and shuts down. Use `run!` for iterative development. ```julia using QuartoNotebookRunner # Simple one-shot rendering - server is created and destroyed automatically QuartoNotebookRunner.render("report.qmd"; output = "report.ipynb") # With progress display QuartoNotebookRunner.render( "analysis.qmd"; output = "analysis.ipynb", showprogress = true ) ``` -------------------------------- ### Run Notebooks via Server Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Use the Server API to execute a Quarto notebook and save the output as a Jupyter notebook. ```julia julia> using QuartoNotebookRunner julia> server = QuartoNotebookRunner.Server(); julia> QuartoNotebookRunner.run!(server, "notebook.qmd"; output = "notebook.ipynb") julia> QuartoNotebookRunner.close!(server, "notebook.qmd") ``` -------------------------------- ### Server Management Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Methods for initializing and managing the notebook runner server and its worker processes. ```APIDOC ## Server() ### Description Creates a server instance that manages notebook worker processes. Each notebook is assigned an isolated worker process which is reused for subsequent runs. ### Request Example ```julia using QuartoNotebookRunner server = QuartoNotebookRunner.Server() ``` ## close! ### Description Stops worker processes for specific notebooks or the entire server to free resources. ### Parameters - **server** (Server) - Required - The server instance. - **notebook_path** (String) - Optional - Path to the specific notebook to close. If omitted, all workers are closed. ### Request Example ```julia # Close specific notebook QuartoNotebookRunner.close!(server, "report.qmd") # Close all QuartoNotebookRunner.close!(server) ``` ``` -------------------------------- ### Multi-language Code Execution in Quarto Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Shows how to execute Julia, Python, and R code within the same Quarto notebook, including inline code execution. ```markdown --- title: "Multi-language Notebook" --- Julia code: ```{julia} x = [1, 2, 3, 4, 5] y = x .^ 2 ``` Python code (requires PythonCall.jl): ```{python} import numpy as np data = np.array([1, 2, 3, 4, 5]) print(f"Mean: {data.mean()}") ``` R code (requires RCall.jl): ```{r} x <- c(1, 2, 3, 4, 5) summary(x) ``` Inline code works too: The mean is `{python} np.mean([1,2,3])`. ``` -------------------------------- ### Notebook Execution Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Methods for executing Quarto notebooks and rendering output. ```APIDOC ## run! ### Description Evaluates all code cells in a Quarto notebook and outputs results to a Jupyter notebook file or IO stream. ### Parameters - **server** (Server) - Required - The server instance. - **path** (String) - Required - Path to the .qmd file. - **output** (String/IO) - Optional - Destination for the .ipynb output. - **showprogress** (Bool) - Optional - Whether to display a progress bar. - **options** (Dict) - Optional - Execution options including format settings and parameters. ### Request Example ```julia result = QuartoNotebookRunner.run!(server, "analysis.qmd"; output = "analysis.ipynb", showprogress = true) ``` ## render ### Description Provides a one-shot API for rendering a notebook. It automatically creates and destroys a temporary server. ### Request Example ```julia QuartoNotebookRunner.render("report.qmd"; output = "report.ipynb") ``` ``` -------------------------------- ### Format and Changelog Commands Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/CLAUDE.md Use these commands for code formatting and changelog generation during development. ```bash just format # format the entire codebase ``` ```bash just changelog # generate correct PR links for changelog entries ``` -------------------------------- ### Initialize package extensions in src/Foo.jl Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/PackageExtensionCompat/README.md Add this block to the main module file to ensure extensions are loaded correctly across all supported Julia versions. ```julia using PackageExtensionCompat function __init__() @require_extensions end ``` -------------------------------- ### Create Notebook Runner Server Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Creates a server instance to manage isolated notebook worker processes. Workers are created on first run and reused for subsequent executions. ```julia using QuartoNotebookRunner # Create a server to manage notebook workers server = QuartoNotebookRunner.Server() # Server manages isolated worker processes for each notebook # Workers are created on first run and reused for subsequent runs ``` -------------------------------- ### Quarto Notebook Caching Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Demonstrates enabling notebook caching in Quarto to avoid re-evaluation when code or frontmatter hasn't changed. Cache invalidation conditions are noted. ```markdown --- title: "Cached Analysis" execute: cache: true --- ```{julia} # This expensive computation will be cached using CSV, DataFrames data = CSV.read("large_dataset.csv", DataFrame) result = expensive_analysis(data) ``` ```{julia} # Results are reused if code above hasn't changed summarize(result) ``` ``` -------------------------------- ### Implement Package Extension Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Uses Requires.jl to load extension code when a specific package is loaded in a notebook. ```julia function __init__() @require QuartoNotebookWorker="38328d9c-a911-4051-bc06-3f7f556ffeda" include("extension.jl") end ``` -------------------------------- ### Enable Shared Worker Process in Notebook Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Enable sharing of a worker process for multiple notebooks with compatible configurations via frontmatter. This improves resource utilization. ```markdown --- title: "Report Part 1" julia: share_worker_process: true exeflags: ["--threads=4"] --- ```{julia} # This notebook shares a worker with other notebooks # that have the same julia configuration using SharedData process_part1() ``` ``` -------------------------------- ### Execute Notebook with run! Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Evaluates code cells in a Quarto notebook and saves results to a Jupyter notebook file. Code blocks are evaluated in a new Julia Module on each run. Supports custom options and output to IO streams. ```julia using QuartoNotebookRunner server = QuartoNotebookRunner.Server() # Run a notebook and save output to .ipynb file result = QuartoNotebookRunner.run! server, "analysis.qmd"; output = "analysis.ipynb", showprogress = true ) # Run with custom options passed from Quarto options = Dict{String,Any}( "format" => Dict( "execute" => Dict( "fig-width" => 8, "fig-height" => 6, "fig-format" => "png", "fig-dpi" => 150, "error" => true, # Continue on errors "eval" => true # Evaluate code cells ) ), "params" => Dict("alpha" => 0.05, "dataset" => "training") ) result = QuartoNotebookRunner.run! server, "notebook.qmd"; output = "output.ipynb", options = options ) # Output can also be an IO stream open("result.ipynb", "w") do io QuartoNotebookRunner.run!(server, "notebook.qmd"; output = io) end ``` -------------------------------- ### Capture standard output and return value Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/IOCapture/README.md Use IOCapture.capture to execute a function and retrieve its return value along with captured stdout. ```julia-repl julia> c = IOCapture.capture() do println("test") return 42 end; julia> c.value, c.output (42, "test\n") ``` -------------------------------- ### Socket Server Forceclose Command Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt JSON message to forcibly terminate a running notebook. ```json // Forceclose command - forcibly terminate a running notebook { "type": "forceclose", "content": "/absolute/path/to/notebook.qmd" } ``` -------------------------------- ### Implement expand for Replicate type Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/README.md Defines the expand method to generate multiple cells from a Replicate instance. ```julia import PackageName import QuartoNotebookWorker function QuartoNotebookWorker.expand(r::PackageName.Replicate) # Return a list of notebook `Cell`s to be rendered. return [QuartoNotebookWorker.Cell(r.value) for _ in 1:r.n] end ``` -------------------------------- ### Demonstrate error with closed stream Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/IOCapture/README.md Attempting to use captured stdout/stderr streams outside the capture block results in an IOError. ```julia-repl julia> c = IOCapture.capture() do return stdout end; julia> println(c.value, "test") ERROR: IOError: stream is closed or unusable Stacktrace: [1] check_open at ./stream.jl:328 [inlined] [2] uv_write_async(::Base.PipeEndpoint, ::Ptr{UInt8}, ::UInt64) at ./stream.jl:959 ... ``` -------------------------------- ### Close leftover Julia processes Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/revise/README.md Force close any remaining Julia server processes if the preview command was terminated. ```shell $ just close ``` -------------------------------- ### Observable JavaScript Integration with ojs_define Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Demonstrates how to make Julia data available to ObservableJS cells in Quarto using the `ojs_define` function. ```julia # In a Quarto notebook cell: # ```{julia} using DataFrames # Create some data df = DataFrame( x = 1:10, y = rand(10), category = repeat(["A", "B"], 5) ) # Make data available to OJS cells olds_define( mydata = df, config = Dict("threshold" => 0.5, "title" => "Analysis"), values = [1, 2, 3, 4, 5] ) # ``` # Then in an OJS cell: # ```{ojs} # Plot.plot({ # marks: [ # Plot.dot(mydata, {x: "x", y: "y", fill: "category"}) # ] # }) # ``` ``` -------------------------------- ### Conditional Module Evaluation with @require Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md Use @require with @eval to conditionally load and use a module. This can help leverage precompilation for the conditionally loaded code. ```julia function __init__() @require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" @eval using MyGluePkg end ``` -------------------------------- ### Conditional Code Inclusion with @require Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md Include external Julia code files conditionally using @require within the __init__ method. This is useful for organizing larger amounts of glue code. ```julia function __init__() @require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" include("glue.jl") end ``` -------------------------------- ### Define add_require function Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md Implement this function in your package to receive notifications about @require actions. ```julia add_require(sourcefile, modcaller, id, modname, expr) ``` -------------------------------- ### Demonstrate limitation with stored stdout Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/IOCapture/README.md Capturing fails when printing to a stored reference of the original stdout object. ```julia-repl julia> const original_stdout = stdout; julia> c = IOCapture.capture() do println("output to stdout") println(original_stdout, "output to original stdout") end; output to original stdout julia> c.output "output to stdout\n" ``` -------------------------------- ### Socket Server Close Command Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt JSON message to close a specific notebook worker by its file path. ```json // Close command - close a specific notebook worker { "type": "close", "content": "/absolute/path/to/notebook.qmd" } ``` -------------------------------- ### Quarto Notebook Julia Code Cell Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Demonstrates accessing parameters and basic plotting within a Julia code cell in a Quarto notebook. ```julia # Access parameters as constants println("Using alpha = ", alpha) println("Dataset: ", dataset) ``` ```julia #| eval: true #| echo: true #| fig-cap: "Sample visualization" #| fig-width: 8 #| fig-height: 6 using Plots x = 1:100 plot(x, sin.(x .* alpha), title = "Analysis") ``` ```julia #| eval: false # This cell won't be executed expensive_computation() ``` -------------------------------- ### Nested Requirements for Multiple Dependencies Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md Handle features that depend on multiple packages by nesting @require statements. The inner requirement is only evaluated if the outer one is met. ```julia module TestRequires using Requires function __init__() @require Images="916415d5-f1e6-5110-898d-aaa5f9f070e0" begin @require Revise="295af30f-e4ad-537b-8983-00126c2a3abe" println("Got both!") end end end # module ``` -------------------------------- ### Socket Server Status Command Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt JSON message to request server and worker information. ```json // Status command - get server and worker information { "type": "status", "content": "" } ``` -------------------------------- ### Conditional Function Definition with @require Source: https://github.com/pumasai/quartonotebookrunner.jl/blob/main/src/QuartoNotebookWorker/src/vendor/Requires/README.md Use @require within the __init__ method to define a new function method that is only available when a specified package (e.g., Gadfly) is loaded. The package's UUID is used for identification. ```julia module MyPkg # lots of code myfunction(::MyType) = Textual() function __init__() @require Gadfly="c91e804a-d5a3-530f-b6f0-dfbca275c004" myfunction(::Gadfly.Plot) = Graphical() end end # module ``` -------------------------------- ### Socket Server Stop Command Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt JSON message to shut down the socket server. ```json // Stop command - shutdown the server { "type": "stop", "content": "" } ``` -------------------------------- ### Close Notebook Workers with close! Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Stops worker processes for specific notebooks or the entire server to free resources. Use this when done with a notebook or to clean up the server. ```julia using QuartoNotebookRunner server = QuartoNotebookRunner.Server() # Run a notebook QuartoNotebookRunner.run!(server, "report.qmd"; output = "report.ipynb") # Close the specific notebook worker QuartoNotebookRunner.close!(server, "report.qmd") # Or close all workers and clean up the entire server QuartoNotebookRunner.close!(server) ``` -------------------------------- ### Socket Server JSON Message Format Source: https://context7.com/pumasai/quartonotebookrunner.jl/llms.txt Defines the structure for JSON messages sent to the socket server, including HMAC signing for security. ```json // Message format (each message must be HMAC-signed) { "hmac": "base64_encoded_hmac256_of_payload", "payload": "{\"type\": \"run\", \"content\": \"/path/to/notebook.qmd\"}" } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.