Skip to content

Commit

Permalink
Merge pull request #23 from invenia/mz/namedtuple
Browse files Browse the repository at this point in the history
support passing a `NamedTuple` to `with_checkpoint_tags`
  • Loading branch information
mzgubic authored May 14, 2021
2 parents 0485d7c + b4f94b5 commit d8c15b9
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Checkpoints"
uuid = "b4a3413d-e481-5afc-88ff-bdfbd6a50dce"
authors = "Invenia Technical Computing Corporation"
version = "0.3.6"
version = "0.3.7"

[deps]
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
Expand Down
2 changes: 2 additions & 0 deletions src/Checkpoints.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ include("deprecated.jl")

"""
with_checkpoint_tags(f::Function, context_tags::Pair...)
with_checkpoint_tags(f::Function, context_tags::NamedTuple)
Runs the function `f`, tagging any [`checkpoint`](@ref)s created by `f` with the `context_tags`.
This is normally used via the do-block form:
Expand All @@ -53,6 +54,7 @@ Duplicate tags are repeated, not overwritten.
function with_checkpoint_tags(f::Function, context_tags::Pair...)
with_context(f, CONTEXT_TAGS => (CONTEXT_TAGS[]..., context_tags...))
end
with_checkpoint_tags(f::Function, context_tags::NamedTuple) = with_checkpoint_tags(f, pairs(context_tags)...)

"""
available() -> Vector{String}
Expand Down
8 changes: 8 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,14 @@ Distributed.addprocs(5)
@test isfile(joinpath(path, "tag=a", "date=2017-01-01", "TestPkg", "bar.jlso"))
end

@testset "NamedTuple tags" begin
tags = (tag1="some", tag2="thing")
with_checkpoint_tags(tags) do
TestPkg.bar(a)
end
@test isfile(joinpath(path, "tag1=some", "tag2=thing", "date=2017-01-01", "TestPkg", "bar.jlso"))
end

@testset "nested tags" begin
@testset "different tags" begin
with_checkpoint_tags(:first => "first") do
Expand Down

0 comments on commit d8c15b9

Please sign in to comment.