Skip to content

Commit

Permalink
closes #228
Browse files Browse the repository at this point in the history
  • Loading branch information
tlienart committed Jul 17, 2023
1 parent 659e3e5 commit 5b47847
Show file tree
Hide file tree
Showing 7 changed files with 75 additions and 7 deletions.
2 changes: 1 addition & 1 deletion src/context/code/notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ increment!(nb::Notebook) = (nb.cntr_ref[] += 1)
reset_counter!(nb::Notebook) = (nb.cntr_ref[] = 1)

"""
reset_code_notebook!(nb)
reset_notebook!(nb)
Clear code notebooks so that it can be re-evaluated from scratch in case the
page variable `ignore_cache` is used for instance.
Expand Down
10 changes: 6 additions & 4 deletions src/context/code/notebook_code.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,15 @@ function eval_code_cell!(
cell_code = string(cell_code)
cell_hash = hash(cell_code) |> string

ignore_cache = getvar(ctx, :ignore_cache, false)

# if the cell_index is within the range of cell indexes, we replace the
# name with the current cell name to guarantee we're using the latest name.
if cell_index <= length(nb.code_names)
nb.code_names[cell_index] = cell_name
# skip cell if previously seen and unchanged
if isunchanged(nb, cell_index, cell_code) && !force
@info " ⏩ skipping cell $cell_name (unchanged)"
if !(ignore_cache | force) && isunchanged(nb, cell_index, cell_code)
@info " ⏩ skipping cell $(hl(cell_name, :yellow)) (unchanged)"
increment!(nb)
return
end
Expand All @@ -58,7 +60,7 @@ function eval_code_cell!(
# happen to already have a mapping for it
if indep
if cell_code in keys(nb.indep_code)
@info " ⏩ skipping cell $cell_name (independent 🌴)"
@info " ⏩ skipping cell $(hl(cell_name, :yellow)) (independent 🌴)"
code_pair = CodeCodePair((cell_code, nb.indep_code[cell_code]))
return finish_cell_eval!(nb, code_pair, indep)
end
Expand All @@ -80,7 +82,7 @@ function eval_code_cell!(
# keep track of vars assignments or whatever as they
# can't have changed
for tmp_idx = 1:cell_index-1
@info " 💦 refreshing cell $(nb.code_names[tmp_idx])..."
@info " 💦 refreshing cell $(hl(nb.code_names[tmp_idx], :yellow))..."
_eval_code_cell(
nb.mdl,
nb.code_pairs[tmp_idx].code,
Expand Down
1 change: 1 addition & 0 deletions src/context/default_context.jl
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ const DefaultLocalVarsAlias = Alias(
:fd_ctime => :_creation_time,
:fd_mtime => :_modification_time,
:reeval => :ignore_cache,
:force_eval_all => :ignore_cache,
:hasmath => :_hasmath,
:hascode => :_hascode,
:rss_description => :rss_descr,
Expand Down
4 changes: 2 additions & 2 deletions src/process/md/pass_1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -138,8 +138,8 @@ function reset_page_context!(
setvar!(lc, :_hasmath, false)
setvar!(lc, :_hascode, false)

# in the context of "ignore_cache", reset the notebook
reset_notebook && reset_code_notebook!(lc)
# in the context of "ignore_cache", reset both notebooks
reset_notebook && reset_both_notebooks!(lc)

return state
end
Expand Down
63 changes: 63 additions & 0 deletions test/indir/eval_order.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
include(joinpath(@__DIR__, "..", "utils.jl"))

@test_in_dir "_order" "i228" begin
txt = raw"""
```!a
a = 5
```
A \htmlshow{a}
```!b
b = a + 5
```
B \htmlshow{b}
```!c
a = 7
```
C \htmlshow{c}
"""

write(FOLDER/"config.md","")
write(FOLDER/"utils.jl","")
write(FOLDER/"index.md", txt)

task = @async serve(FOLDER, launch=false)
sleep(2)

for e in ("A 5", "B 10", "C 7")
@test output_contains(FOLDER, "", e)
end

println("<>")

# now we only modify the second cell; since the
# cache is enabled, it's the last value of `a` that
# is used (see #227)
txt = replace(txt, "b = a + 5" => "b = a + 1")
write(FOLDER/"index.md", txt)
sleep(1)

for e in ("A 5", "B 8", "C 7")
@test output_contains(FOLDER, "", e)
end

println("<>")

# finally, we re-do this but with the force caching
txt = """
+++
force_eval_all = true
+++
$txt
"""
write(FOLDER/"index.md", txt)
sleep(1)
for e in ("A 5", "B 6", "C 7")
@test output_contains(FOLDER, "", e)
end

schedule(task, InterruptException(), error=true)
sleep(1)
end

# XXX stopping here for now, need to continue this

1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ end
include(p/"hfuns.jl")
include(p/"rss.jl")
include(p/"sitemap-robots.jl")
include(p/"eval_order.jl")
end

end
1 change: 1 addition & 0 deletions test/utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ using Dates
using Logging
using Colors
import Base: (//)
using Base.Threads

import LiveServer
X = Xranklin;
Expand Down

0 comments on commit 5b47847

Please sign in to comment.