mirror of https://github.com/mpastell/Weave.jl
Merge pull request #316 from JunoLab/avi/dev
ensure Weave display pops out even if an internal err occurspull/318/head
commit
ac486c5e1d
61
src/run.jl
61
src/run.jl
|
@ -87,45 +87,42 @@ function Base.run(
|
||||||
report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes, throw_errors)
|
report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes, throw_errors)
|
||||||
pushdisplay(report)
|
pushdisplay(report)
|
||||||
|
|
||||||
if cache != :off && cache != :refresh
|
try
|
||||||
cached = read_cache(doc, cache_path)
|
if cache !== :off && cache !== :refresh
|
||||||
cached == nothing && @info("No cached results found, running code")
|
cached = read_cache(doc, cache_path)
|
||||||
else
|
cached === nothing && @info "No cached results found, running code"
|
||||||
cached = nothing
|
|
||||||
end
|
|
||||||
|
|
||||||
executed = Any[]
|
|
||||||
n = length(doc.chunks)
|
|
||||||
|
|
||||||
for i = 1:n
|
|
||||||
chunk = doc.chunks[i]
|
|
||||||
|
|
||||||
if isa(chunk, CodeChunk)
|
|
||||||
options = merge(doc.chunk_defaults, chunk.options)
|
|
||||||
merge!(chunk.options, options)
|
|
||||||
end
|
|
||||||
|
|
||||||
restore = (cache == :user && typeof(chunk) == CodeChunk && chunk.options[:cache])
|
|
||||||
|
|
||||||
if cached != nothing && (cache == :all || restore)
|
|
||||||
result_chunks = restore_chunk(chunk, cached)
|
|
||||||
else
|
else
|
||||||
result_chunks = run_chunk(chunk, doc, report, mod)
|
cached = nothing
|
||||||
end
|
end
|
||||||
|
|
||||||
executed = [executed; result_chunks]
|
executed = []
|
||||||
end
|
for chunk in doc.chunks
|
||||||
|
if isa(chunk, CodeChunk)
|
||||||
|
options = merge(doc.chunk_defaults, chunk.options)
|
||||||
|
merge!(chunk.options, options)
|
||||||
|
end
|
||||||
|
|
||||||
doc.header_script = report.header_script
|
restore = (cache === :user && typeof(chunk) == CodeChunk && chunk.options[:cache])
|
||||||
|
|
||||||
popdisplay(report)
|
result_chunks = if cached != nothing && (cache === :all || restore)
|
||||||
|
restore_chunk(chunk, cached)
|
||||||
|
else
|
||||||
|
run_chunk(chunk, doc, report, mod)
|
||||||
|
end
|
||||||
|
|
||||||
# Clear variables from used sandbox
|
executed = [executed; result_chunks]
|
||||||
mod == :sandbox && clear_sandbox(SandBox)
|
end
|
||||||
doc.chunks = executed
|
|
||||||
|
|
||||||
if cache != :off
|
doc.header_script = report.header_script
|
||||||
write_cache(doc, cache_path)
|
# Clear variables from used sandbox
|
||||||
|
mod === :sandbox && clear_sandbox(SandBox)
|
||||||
|
doc.chunks = executed
|
||||||
|
|
||||||
|
cache !== :off && write_cache(doc, cache_path)
|
||||||
|
catch err
|
||||||
|
rethrow(err)
|
||||||
|
finally
|
||||||
|
popdisplay(report) # ensure display pops out even if internal error occurs
|
||||||
end
|
end
|
||||||
|
|
||||||
return doc
|
return doc
|
||||||
|
|
Loading…
Reference in New Issue