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

support passing a NamedTuple to with_checkpoint_tags #23

Merged
merged 4 commits into from
May 14, 2021
Merged
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
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
glennmoy marked this conversation as resolved.
Show resolved Hide resolved
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