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

Workaround for indexing S3Path with "." relpath #42

Merged
merged 3 commits into from
Dec 9, 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.16"
version = "0.3.17"

[deps]
AWSS3 = "1c724243-ef5b-51ab-93f4-b0a88ac62a95"
Expand Down
21 changes: 14 additions & 7 deletions src/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@ struct IndexEntry
end

function IndexEntry(filepath::AbstractPath, base_dir)
segments = relpath(dirname(filepath), base_dir).segments

prefixes = filter(!contains("="), segments)
tags = map(filter(contains("="), segments)) do seg
tag, val = split(seg, "="; limit=2)
return Symbol(tag)=>val
if dirname(filepath) == base_dir
# workaround for relpath erroring on equal S3Paths
# https://github.com/rofinn/FilePathsBase.jl/issues/156
prefixes = ()
tags = ()
else
segments = relpath(dirname(filepath), base_dir).segments

prefixes = filter(!contains("="), segments)
tags = map(filter(contains("="), segments)) do seg
tag, val = split(seg, "="; limit=2)
return Symbol(tag)=>val
end
end
checkpoint_name = filename(filepath)
return IndexEntry(filepath, checkpoint_name, prefixes, tags)
Expand Down Expand Up @@ -70,7 +77,7 @@ prefixes(x::IndexEntry) = getfield(x, :prefixes)
"""
checkpoint_fullname(x::IndexEntry)

The full name of the checkpoint output file, including [`prefixes`](@ref), and
The full name of the checkpoint output file, including [`prefixes`](@ref), and
[`checkpoint_name`](@ref).
If the checkpoint was saved using `checkpoint(Forecasters, "forecasts", ...)` then
`checkpoint_fullname` will return `"Forecasters.forecasts"`.
Expand Down
12 changes: 12 additions & 0 deletions test/indexing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,18 @@
end
end

@testset "no module, no tags" begin
Checkpoints.register(["bar"])
mktempdir() do path
Checkpoints.config("bar", path)
checkpoint("bar", 1)
index = index_checkpoint_files(path)
entry = only(index)
@test isempty(tags(entry))
@test isempty(prefixes(entry))
end
end

@testset "nonexistent dir" begin
@test_throws ArgumentError index_checkpoint_files("nonexistent_dir")
end
Expand Down