mirror of https://github.com/mpastell/Weave.jl
Fix bug in Sandboxing, run code in sandbox module by default
parent
b136fa615d
commit
f90547cee6
|
@ -64,8 +64,8 @@ Weave an input document to output file.
|
|||
Julia working directory, `"somepath"`: output directory as a String e.g `"/home/mpastell/weaveout"` or filename as
|
||||
string e.g. ~/outpath/outfile.tex.
|
||||
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS
|
||||
* `mod`: Module where Weave `eval`s code. Defaults to `Main`. Use `:sandbox`
|
||||
to create new sandbox module for source.
|
||||
* `mod`: Module where Weave `eval`s code. Defaults to `:sandbox`
|
||||
to create new sandbox module, you can also pass a module e.g. `Main`.
|
||||
* `fig_path`: where figures will be generated, relative to out_path
|
||||
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
||||
* `cache_path`: where of cached output will be saved.
|
||||
|
@ -82,7 +82,7 @@ Weave an input document to output file.
|
|||
"""
|
||||
function weave(source ; doctype = :auto, plotlib=:auto,
|
||||
informat=:auto, out_path=:doc, args = Dict(),
|
||||
mod::Union{Module, Symbol} = Main,
|
||||
mod::Union{Module, Symbol} = :sandbox,
|
||||
fig_path = "figures", fig_ext = nothing,
|
||||
cache_path = "cache", cache=:off,
|
||||
throw_errors = false,
|
||||
|
|
13
src/run.jl
13
src/run.jl
|
@ -1,7 +1,7 @@
|
|||
|
||||
"""
|
||||
run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
|
||||
mod::Union{Module, Symbol} = Main, out_path=:doc,
|
||||
mod::Union{Module, Symbol} = :sandbox, out_path=:doc,
|
||||
args=Dict(), fig_path = "figures", fig_ext = nothing,
|
||||
cache_path = "cache", cache = :off, throw_errors=false)
|
||||
|
||||
|
@ -13,8 +13,8 @@ Run code chunks and capture output from parsed document.
|
|||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
||||
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
|
||||
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS.
|
||||
* `mod`: Module where Weave `eval`s code. Defaults to `Main`. Use `:sandbox`
|
||||
to create new sandbox module for source.
|
||||
* `mod`: Module where Weave `eval`s code. Defaults to `:sandbox`
|
||||
to create new sandbox module, you can also pass a module e.g. `Main`.
|
||||
* `fig_path`: where figures will be generated, relative to out_path
|
||||
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
||||
* `cache_path`: where of cached output will be saved.
|
||||
|
@ -24,7 +24,7 @@ Run code chunks and capture output from parsed document.
|
|||
**Note:** Run command from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
|
||||
"""
|
||||
function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
|
||||
mod::Union{Module, Symbol} = Main, out_path=:doc,
|
||||
mod::Union{Module, Symbol} = :sandbox, out_path=:doc,
|
||||
args=Dict(), fig_path = "figures", fig_ext = nothing,
|
||||
cache_path = "cache", cache = :off, throw_errors=false)
|
||||
#cache :all, :user, :off, :refresh
|
||||
|
@ -51,9 +51,8 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto,
|
|||
|
||||
#New sandbox for each document with args exposed
|
||||
if mod == :sandbox
|
||||
sandbox = "ReportSandBox$(rcParams[:doc_number])"
|
||||
eval(Meta.parse("module $sandbox\nend"))
|
||||
mod = eval(Meta.parse(sandbox))
|
||||
sandbox = "WeaveSandBox$(rcParams[:doc_number])"
|
||||
mod = Core.eval(Main, Meta.parse("module $sandbox\nend"))
|
||||
end
|
||||
@eval mod WEAVE_ARGS = Dict()
|
||||
merge!(mod.WEAVE_ARGS, args)
|
||||
|
|
|
@ -31,5 +31,5 @@ wdoc = weavestring(smod)
|
|||
@test wdoc.chunks[2].output == "x"
|
||||
|
||||
sdoc = weavestring(smod, mod=:sandbox)
|
||||
@test occursin(r"Weave.ReportSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output)
|
||||
@test occursin(r"Main.WeaveSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output)
|
||||
@test sdoc.chunks[2].output == "x"
|
||||
|
|
Loading…
Reference in New Issue