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

Add optional softscoping #471

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
1 change: 1 addition & 0 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ REPL = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb"
RelocatableFolders = "05181044-ff0b-4ac5-8273-598c1e38db00"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"
Serialization = "9e88b42a-f829-5b0c-bbe9-9e923198166b"
SoftGlobalScope = "b85f4697-e234-5449-a836-ec8e2f98b302"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Expand Down
2 changes: 1 addition & 1 deletion src/Weave.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module Weave

using Highlights, Mustache, Requires, Pkg, REPL, RelocatableFolders, Base64
using Highlights, Mustache, Requires, Pkg, REPL, RelocatableFolders, Base64, SoftGlobalScope

# directories
const PKG_DIR = normpath(@__DIR__, "..")
Expand Down
1 change: 1 addition & 0 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const _DEFAULT_PARAMS = Dict{Symbol,Any}(
:fig_env => nothing,
:out_width => nothing,
:out_height => nothing,
:softscope => false,
)
const DEFAULT_PARAMS = deepcopy(_DEFAULT_PARAMS) # might be changed at runtime

Expand Down
2 changes: 1 addition & 1 deletion src/reader/notebook.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ function parse_notebook(document_body)
doc_no = 0

# TODO: handle some of options ?
options = Dict{Symbol,Any}()
options = Dict{Symbol,Any}(:softscope => true)
opt_string = ""

chunks = map(nb["cells"]) do cell
Expand Down
7 changes: 4 additions & 3 deletions src/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ function run_code(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module)
code = chunk.content
path = doc.path
error = chunk.options[:error]
softscope = chunk.options[:softscope]
codes = chunk.options[:term] ? split_code(code) : [code]
capture = code -> capture_output(code, mod, path, error, report)
capture = code -> capture_output(code, mod, path, error, report, softscope)
return capture.(codes)
end

Expand All @@ -207,7 +208,7 @@ function split_code(code)
return res
end

function capture_output(code, mod, path, error, report)
function capture_output(code, mod, path, error, report, softscope=false)
reset_report!(report)

old = stdout
Expand All @@ -217,7 +218,7 @@ function capture_output(code, mod, path, error, report)
local out = nothing
task_local_storage(:SOURCE_PATH, path) do
try
obj = include_string(mod, code, path) # TODO: fix line number
obj = softscope ? softscope_include_string(mod, code, path) : include_string(mod, code, path) # TODO: fix line number
!isnothing(obj) && !REPL.ends_with_semicolon(code) && display(obj)
catch _err
err = unwrap_load_err(_err)
Expand Down