Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow chunk output to be re-evaluated #246

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ const defaultParams =
:fig_env=> nothing,
:out_width=> nothing,
:out_height=> nothing,
:skip=>false
:skip=>false,
:output_as_code=>false,
:output_eval=>true
)
)
#This one can be changed at runtime, initially a copy of defaults
Expand Down
9 changes: 8 additions & 1 deletion src/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)

#Run post_execute chunks
for hook in postexecute_hooks
chunk = Compat.invokelatest(hook, chunk)
chunk = Compat.invokelatest(hook, chunk)
end

if chunk.options[:term]
Expand All @@ -300,6 +300,13 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
chunks = collect_results(chunk, ScriptResult())
end

if (chunk.options[:output_as_code])
newchunk = deepcopy(chunk)
newchunk.options[:output_as_code] = false
newchunk.options[:eval] = chunk.options[:output_eval]
newchunk.content = prod([r.stdout for r in chunk.result])
chunks = eval_chunk(newchunk, report, SandBox)
end
#else
# chunk.options[:fig] && (chunk.figures = copy(report.figures))
#end
Expand Down
4 changes: 4 additions & 0 deletions test/documents/codefile.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
using InteractiveUtils
@code_native +(1.0, π)
using Test
@test 1 == 1
7 changes: 4 additions & 3 deletions test/documents/jupyter_test.jmd
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ And here's some code
Here's some more complicated code

```julia
@code_native +(1.0, π)
using Test
@test 1 == 1
using InteractiveUtils
@code_native +(1.0, π)
using Test
@test 1 == 1
```
17 changes: 17 additions & 0 deletions test/documents/output_as_code.jmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
Here's some text

And here's some code

```julia; output_as_code=true
print(" x = 1
y = 2
@show x + y
")
```

Here's some more complicated code

```julia; output_as_code=true
txt = read(WEAVE_ARGS["filename"], String)
print(txt)
```
14 changes: 14 additions & 0 deletions test/output_as_code.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
dir = @__DIR__
refjmd = joinpath(dir, "documents", "jupyter_test.jmd")
testjmd = joinpath(dir, "documents", "output_as_code.jmd")


Weave.weave(refjmd, doctype="pandoc")
refresult = read(joinpath(dir, "documents", "jupyter_test.md"), String)

Weave.weave(testjmd, doctype="pandoc",
args=Dict("filename" => joinpath(dir, "documents", "codefile.jl")))
result = read(joinpath(dir, "documents", "output_as_code.md"), String)

@test result == refresult

4 changes: 4 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,10 @@ using Test
include("inline_test.jl")
end

@testset "Output as code" begin
@info("Testing output as code")
include("output_as_code.jl")
end
# @testset "Notebooks" begin
# @info("Testing Jupyter options")
# include("notebooks.jl")
Expand Down