Skip to content

Commit 7fd5636

Browse files
Allow server and worker code to be Revised during quarto preview (#263)
* Allow server code to be `Revise`d during `quarto preview` * Add support for revising the worker package code * Ensure `Revise` changes apply to every `render` call * Move some code out of `worker_init` and into startup.jl * Drop some `invokelatest` calls, update docs
1 parent 066badf commit 7fd5636

File tree

14 files changed

+154
-24
lines changed

14 files changed

+154
-24
lines changed

Project.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1"
1414
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
1515
Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f"
1616
PrecompileTools = "aea7be01-6a6a-4083-8856-8a6e6704d82a"
17+
Preferences = "21216c6a-2e73-6563-6e65-726566657250"
1718
ProgressLogging = "33c8b6b6-d38a-422a-b730-caa89a2f386c"
1819
REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
1920
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
@@ -34,6 +35,7 @@ JSON3 = "1"
3435
Logging = "1.6"
3536
Pkg = "1.6"
3637
PrecompileTools = "1"
38+
Preferences = "1"
3739
ProgressLogging = "0.1.4"
3840
REPL = "1.6"
3941
Random = "1.6"

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,11 @@ Import `RemoteREPL` into a notebook cell and run
124124
`Main.QuartoNotebookWorker.remote_repl()`. Then in a separate REPL run
125125
`RemoteREPL.connect_repl()` to connect to the notebook process for debugging.
126126

127+
### Integration with `Revise.jl`
128+
129+
See [revise/README.md](./revise/README.md) for information on how to use
130+
`Revise` with this package while developing changes.
131+
127132
### Adding package "integrations"
128133

129134
Some packages require custom integrations to be written to make them behave as

justfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
default:
2+
just -l
3+
4+
changelog:
5+
julia --project=.ci .ci/changelog.jl
6+
7+
close:
8+
kill $(ps aux | grep '[j]ulia.*quartonotebookrunner\.jl' | awk '{print $2}')
9+
10+
format:
11+
julia --project=.ci .ci/format.jl
12+
13+
revise *args:
14+
julia --startup-file=no --project=revise -e 'import Pkg; Pkg.develop(; path = ".")'
15+
julia --startup-file=no revise/quarto.jl {{args}}

revise/LocalPreferences.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[QuartoNotebookRunner]
2+
enable_revise = true

revise/Project.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
[deps]
2+
QuartoNotebookRunner = "4c0109c6-14e9-4c88-93f0-2b974d3468f4"
3+
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"

revise/README.md

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# `Revise` integration for `quarto preview`
2+
3+
This environment allows for running `QuartoNotebookRunner` with `Revise`
4+
enabled. That means that you can edit code within the `QuartoNotebookRunner`
5+
module that a `quarto` process is using for `engine: julia` notebooks and have
6+
those changes take effect on the next render request that is triggered by a
7+
notebook file change. Without this feature you need to manually close and
8+
restart the `julia` process on each change.
9+
10+
## Usage
11+
12+
A `justfile` is provided that will start a `quarto` server with `Revise` enabled.
13+
14+
```
15+
$ just revise quarto preview filename.qmd
16+
```
17+
18+
If you terminate the command and need to force close any leftover `julia` server
19+
processes then run:
20+
21+
```
22+
$ just close
23+
```
24+
25+
## `QuartoNotebookWorker` code revision
26+
27+
To enable `Revise` for the `QuartoNotebookWorker` module, you must have
28+
`Revise` installed as a dependency in the notebook environment, it cannot be a
29+
global environment dependency since this is not part of the `LOAD_PATH` for
30+
notebooks. Then set the `QUARTO_ENABLE_REVISE=true` environment variable for
31+
your notebook in the `julia.env` frontmatter key.

revise/quarto.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
isempty(ARGS) && error("No arguments provided")
2+
run(addenv(`$ARGS`, "QUARTO_JULIA_PROJECT" => @__DIR__))

src/QuartoNotebookRunner.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import IterTools
2727
import JSON3
2828
import Logging
2929
import PrecompileTools
30+
import Preferences
3031
import ProgressLogging
3132
import REPL
3233
import Random
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
module QuartoNotebookWorkerReviseExt
22

33
import Revise
4-
import QuartoNotebookWorker
4+
import QuartoNotebookWorker as QNW
55

66
function __init__()
77
@debug "extension has been loaded" Revise QuartoNotebookWorker
88
end
99

10+
function QNW._revise_hook(::Nothing)
11+
isempty(Revise.revision_queue) || Base.invokelatest(Revise.revise; throw = true)
12+
return nothing
13+
end
14+
1015
end

src/QuartoNotebookWorker/src/refresh.jl

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ function refresh!(path, original_options, options = original_options)
2424
return nothing
2525
end
2626

27+
revise_hook() = _revise_hook(nothing)
28+
_revise_hook(::Any) = nothing
29+
2730
function rget(dict, keys, default)
2831
value = dict
2932
for key in keys

0 commit comments

Comments
 (0)