Load JLD2 and FileIO only when cache is used

pull/119/head
Matti Pastell 2018-01-07 20:01:18 +02:00
parent d19d6b6d81
commit 88d8665e03
2 changed files with 5 additions and 3 deletions

View File

@ -1,16 +1,16 @@
import JLD2, FileIO
#FileIO and JLD2 are imported only if cache is used
function write_cache(doc::WeaveDoc, cache_path)
cache_dir = joinpath(doc.cwd, cache_path)
isdir(cache_dir) || mkpath(cache_dir)
FileIO.save(joinpath(cache_dir, doc.basename * ".jld2"), Dict("doc" => doc))
Base.invokelatest(FileIO.save, joinpath(cache_dir, doc.basename * ".jld2"), Dict("doc" => doc))
return nothing
end
function read_cache(doc::WeaveDoc, cache_path)
name = joinpath(doc.cwd, cache_path, doc.basename * ".jld2")
isfile(name) || return nothing
return FileIO.load(name, "doc")
return Base.invokelatest(FileIO.load, name, "doc")
end
function restore_chunk(chunk::CodeChunk, cached)

View File

@ -37,6 +37,8 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
fig_path = mktempdir(abspath(doc.cwd))
end
cache == :off || @eval import FileIO, JLD2
#This is needed for latex and should work on all output formats
is_windows() && (fig_path = replace(fig_path, "\\", "/"))