Skip to content

Commit

Permalink
improve isjupyter
Browse files Browse the repository at this point in the history
  • Loading branch information
xukai92 committed Apr 28, 2019
1 parent aff16fe commit 27a65a6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src/MLToolkit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export break_stick_ibp, break_logstick_ibp
include("Data/Data.jl")
Reexport.@reexport using .Data
include("scripting.jl")
export parse_args, flatten_dict, @jupyter, @script, checknumerics, @checknumerics
export parse_args, flatten_dict, isjupyter, @jupyter, @script, checknumerics, @checknumerics
include("plotting.jl")
export make_two_y_axes_plot, plot_grayimg, plot_actmat

Expand Down
18 changes: 10 additions & 8 deletions src/scripting.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ function flatten_dict(dict::Dict{T,Any};
return join(["$k$equal_sym$v" for (k,v) in filter(t -> (t[1] in include) && !(t[1] in exclude), dict)], delimiter)
end

isjupyter() = isdefined(Main, :IJulia) && Main.IJulia.inited

"""
@jupyter expr
Execute `expr` if IN Jupyter.
"""
macro jupyter(expr)
return quote
if isdefined(Main, :IJulia) && Main.IJulia.inited
$expr
end
if isjupyter()
return esc(expr)
else
return nothing
end
end

Expand All @@ -33,10 +35,10 @@ end
Execute `expr` if NOT IN Jupyter.
"""
macro script(expr)
return quote
if !(isdefined(Main, :IJulia) && Main.IJulia.inited)
$expr
end
if !isjupyter()
return esc(expr)
else
return nothing
end
end

Expand Down

0 comments on commit 27a65a6

Please sign in to comment.