mirror of https://github.com/mpastell/Weave.jl
Fix PyPlot for 0.6
parent
b66ae83e37
commit
c788f5f15e
11
src/Weave.jl
11
src/Weave.jl
|
@ -1,4 +1,4 @@
|
|||
__precompile__()
|
||||
__precompile__(false)
|
||||
module Weave
|
||||
import Highlights
|
||||
|
||||
|
@ -58,10 +58,10 @@ Weave an input document to output file.
|
|||
See `list_out_formats()`
|
||||
* `plotlib`: `"PyPlot"`, `"Gadfly"` or `nothing`
|
||||
* `informat`: :auto = set based on file extension or set to `"noweb"`, `"markdown"` or `script`
|
||||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`:
|
||||
Julia working directory, `"somepath"`: output directory as a String e.g `"/home/mpastell/weaveout"` or filename as
|
||||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`:
|
||||
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
|
||||
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS
|
||||
* `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.
|
||||
|
@ -120,10 +120,11 @@ function weave(source ; doctype = :auto, plotlib=:auto,
|
|||
doc.cwd == pwd() && (outname = basename(outname))
|
||||
info("Report weaved to $outname")
|
||||
catch e
|
||||
rethrow(e)
|
||||
warn("Something went wrong during weaving")
|
||||
print(e)
|
||||
finally
|
||||
doctype == :auto && (doctype = detect_doctype(doc.source))
|
||||
doctype == :auto && (doctype = detect_doctype(doc.source))
|
||||
if contains(doctype, "2pdf") && cache == :off
|
||||
rm(doc.fig_path, force = true, recursive = true)
|
||||
elseif contains(doctype, "2html")
|
||||
|
|
|
@ -30,11 +30,11 @@ function Base.display(report::Report, data)
|
|||
#Set preferred mimetypes for report based on format
|
||||
for m in report.mimetypes
|
||||
if mimewritable(m, data)
|
||||
info(data)
|
||||
try
|
||||
display(report, m, data)
|
||||
catch
|
||||
warn("Failed to save image in \"$m\" format")
|
||||
#rethrow()
|
||||
continue
|
||||
end
|
||||
#Always show plain text as well for term mode
|
||||
|
|
|
@ -8,7 +8,6 @@ function savefigs_pyplot(report::Report)
|
|||
isdir(figpath) || mkdir(figpath)
|
||||
chunkid = (chunk.options[:name] == nothing) ? chunk.number : chunk.options[:name]
|
||||
#Iterate over all open figures, save them and store names
|
||||
|
||||
|
||||
for fig = plt[:get_fignums]()
|
||||
full_name, rel_name = get_figname(report, chunk, fignum=fig)
|
||||
|
@ -18,5 +17,4 @@ function savefigs_pyplot(report::Report)
|
|||
plt[:draw]()
|
||||
plt[:close]()
|
||||
end
|
||||
#return fignames
|
||||
end
|
||||
|
|
14
src/run.jl
14
src/run.jl
|
@ -10,7 +10,7 @@ Run code chunks and capture output from parsed document.
|
|||
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
|
||||
* `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.
|
||||
* `args`: dictionary of arguments to pass to document. Available as WEAVE_ARGS.
|
||||
* `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.
|
||||
|
@ -168,10 +168,10 @@ end
|
|||
|
||||
function run_inline(inline::InlineCode, report::Report, SandBox::Module)
|
||||
#Make a temporary CodeChunk for running code. Collect results and don't wrap
|
||||
chunk = CodeChunk(inline.content, 0, 0, "", Dict(:hold => true, :wrap => false))
|
||||
chunk = CodeChunk(inline.content, 0, 0, "", Dict(:hold => true, :wrap => false))
|
||||
options = merge(rcParams[:chunk_defaults], chunk.options)
|
||||
merge!(chunk.options, options)
|
||||
|
||||
|
||||
chunks = eval_chunk(chunk, report, SandBox)
|
||||
contains(report.formatdict[:doctype], "2html") && (chunks = embed_figures(chunks, report.cwd))
|
||||
|
||||
|
@ -211,7 +211,11 @@ function run_code(chunk::CodeChunk, report::Report, SandBox::Module)
|
|||
|
||||
#Save figures only in the end of chunk for PyPlot
|
||||
if rcParams[:plotlib] == "PyPlot"
|
||||
savefigs_pyplot(report::Report)
|
||||
#Work around "old world"
|
||||
(@eval savep1(x) = savefigs_pyplot(x))
|
||||
savep2(x) = eval(Expr(:call, function() savep1( x ) end))
|
||||
savep2(report)
|
||||
#savep(report)
|
||||
end
|
||||
|
||||
return results
|
||||
|
@ -269,7 +273,7 @@ end
|
|||
|
||||
|
||||
function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
|
||||
|
||||
|
||||
|
||||
if !chunk.options[:eval]
|
||||
chunk.output = ""
|
||||
|
|
Loading…
Reference in New Issue