Skip to content

Commit

Permalink
Merge pull request #251 from JunoLab/sp/proginterp
Browse files Browse the repository at this point in the history
allow expressions as progress name
  • Loading branch information
pfitzseb authored Mar 7, 2019
2 parents 5320a90 + e3d4297 commit 0f5b2a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/progress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ macro progress(args...)
end

_progress(ex) = _progress("", 0.005, ex)
_progress(name::AbstractString, ex) = _progress(name, 0.005, ex)
_progress(name::Union{AbstractString, Expr}, ex) = _progress(name, 0.005, ex)
_progress(thresh::Real, ex) = _progress("", thresh, ex)

function _progress(name, thresh, ex)
Expand Down Expand Up @@ -103,7 +103,7 @@ function _progress(name, thresh, ex, target, result, loop, iter_vars, ranges, bo
_id = "progress_$(gensym())"
quote
if isactive()
@logmsg($PROGRESSLEVEL, $name, progress=0.0, _id=Symbol($_id))
@logmsg($PROGRESSLEVEL, $(esc(name)), progress=0.0, _id=Symbol($_id))
$target = try
ranges = $(Expr(:vect,esc.(ranges)...))
nranges = length(ranges)
Expand All @@ -118,15 +118,15 @@ function _progress(name, thresh, ex, target, result, loop, iter_vars, ranges, bo
quote
frac = _frac($(Expr(:vect, count_vars...)))
if frac - lastfrac > $thresh
@logmsg($PROGRESSLEVEL, $name, progress=frac, _id=Symbol($_id))
@logmsg($PROGRESSLEVEL, $(esc(name)), progress=frac, _id=Symbol($_id))
lastfrac = frac
end
$body
end
))

finally
@logmsg($PROGRESSLEVEL, $name, progress="done", _id=Symbol($_id))
@logmsg($PROGRESSLEVEL, $(esc(name)), progress="done", _id=Symbol($_id))
end
$result
else
Expand Down
9 changes: 9 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,15 @@ let i = 0, j = 0, x
@test x == nothing
end

let i = 0, j = 0, x
bar = "bar"
x = @progress "foo $bar" for _ = 1:10
i += 1
end
@test i == 10
@test x == nothing
end

let x,y
x = @progress y = [i+3j for i=1:3, j=1:4]
@test y == reshape(4:15,3,4)
Expand Down

0 comments on commit 0f5b2a1

Please sign in to comment.