Skip to content

Commit

Permalink
nicefy deprecatino
Browse files Browse the repository at this point in the history
  • Loading branch information
Miha Zgubic committed May 10, 2021
1 parent 6422e6c commit 84ac8a4
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/Checkpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,28 +77,28 @@ commited later by `commit!(session)`.
Explicitly calling checkpoint on a handler is generally not advised, but is an option.
"""
function checkpoint(name::String, data::Dict{Symbol}; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint(CHECKPOINTS[name], name, data)
end
end

function checkpoint(name::String, data::Pair...; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint(name, Dict(data...))
end
end

function checkpoint(name::String, data; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint(name, Dict(:data => data))
end
end

function checkpoint(prefix::Union{Module, String}, name::String, args...; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint("$prefix.$name", args...)
end
Expand Down
11 changes: 7 additions & 4 deletions src/deprecated.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
function checkpoint_deprecation()
Base.depwarn(
"checkpoint(args...; tag=1) is deprecated, use\n" *
"with_checkpoint_tags(:tag=>1) do\n" *
function checkpoint_deprecation(tags...)
kwargs = join(["$(first(tag))=\"$(last(tag))\"" for tag in tags], ", ")
pairs = join([":$(first(tag)) => \"$(last(tag))\"" for tag in tags], ", ")

isempty(tags) || Base.depwarn(
"checkpoint(args...; $(kwargs)) is deprecated, use\n" *
"with_checkpoint_tags($(pairs)) do\n" *
" checkpoint(args...)\n" *
"end\n" *
"instead. Note the use of `Pair`s instead of keyword arguments.",
Expand Down
4 changes: 2 additions & 2 deletions src/handler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ function commit!(handler::Handler{P}, path::P, jlso::JLSO.JLSOFile) where P <: A
end

function checkpoint(handler::Handler, name::String, data::Dict{Symbol}; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
debug(LOGGER, "Checkpoint $name triggered, with context: $(join(CONTEXT_TAGS[], ", ")).")
jlso = JLSO.JLSOFile(Dict{Symbol, Vector{UInt8}}(); handler.settings...)
Expand All @@ -76,7 +76,7 @@ end
Define our no-op conditions just to be safe
=#
function checkpoint(handler::Nothing, name::String, data::Dict{Symbol}; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
debug(LOGGER, "Checkpoint $name triggered, but no handler has been set.")
nothing
Expand Down
6 changes: 3 additions & 3 deletions src/session.jl
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ function commit!(session::Session)
end

function checkpoint(session::Session, data::Dict{Symbol}; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
# No-ops skip when handler is nothing
session.handler === nothing && return nothing
Expand All @@ -61,14 +61,14 @@ function checkpoint(session::Session, data::Dict{Symbol}; tags...)
end

function checkpoint(s::Session, data::Pair...; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint(s, Dict(data...))
end
end

function checkpoint(s::Session, data; tags...)
isempty(tags) || checkpoint_deprecation()
checkpoint_deprecation(tags...)
with_checkpoint_tags(tags...) do
checkpoint(s, Dict(:data => data))
end
Expand Down

0 comments on commit 84ac8a4

Please sign in to comment.