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

Allow access to the artifact path in a relocatable way #32

Merged
merged 8 commits into from
Dec 20, 2024
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 = "TZJData"
uuid = "dc5dba14-91b3-4cab-a142-028a31da12f7"
authors = ["Curtis Vogt <[email protected]>"]
version = "1.3.0+2024b"
version = "1.3.1+2024b"

[deps]
Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33"
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ julia> using TimeZones: TZJFile

julia> function load(tzname)
rel_path = joinpath(split(tzname, '/'))
return open(TZJFile.read, joinpath(TZJData.ARTIFACT_DIR, rel_path), "r")(tzname)
return open(TZJFile.read, joinpath(TZJData.artifact_dir(), rel_path), "r")(tzname)
end
load (generic function with 1 method)

Expand Down
11 changes: 10 additions & 1 deletion src/TZJData.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,14 @@ module TZJData

using Artifacts

const ARTIFACT_DIR = artifact"tzjdata"
# Avoid using a constant to define the artifact directory as this will hardcode the path
# to the location used during pre-compilation which can be problematic if the Julia depot
# relocated afterwards. One scenario where this can occur is when this package is used
# within a system image.
artifact_dir() = artifact"tzjdata"
lcontento marked this conversation as resolved.
Show resolved Hide resolved

lcontento marked this conversation as resolved.
Show resolved Hide resolved
# Deprecation for TZJData.jl v1
Base.@deprecate_binding ARTIFACT_DIR artifact_dir() false

const TZDATA_VERSION = let
artifact_dict = Artifacts.parse_toml(joinpath(@__DIR__, "..", "Artifacts.toml"))
Expand All @@ -11,4 +18,6 @@ const TZDATA_VERSION = let
m !== nothing ? m[:version] : error("Unable to determine tzdata version")
end

precompile(artifact_dir, ())

end
4 changes: 2 additions & 2 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ function sha256sum(tarball_path)
end

@testset "TZJData.jl" begin
@test isdir(TZJData.ARTIFACT_DIR)
@test isdir(TZJData.artifact_dir())
@test occursin(r"^\d{4}[a-z]$", TZJData.TZDATA_VERSION)

@testset "validate unpublished artifact" begin
Expand All @@ -69,7 +69,7 @@ end

@testset "load compiled" begin
cache = Dict{String,Tuple{TimeZone,Class}}()
_reload_cache!(cache, TZJData.ARTIFACT_DIR)
_reload_cache!(cache, TZJData.artifact_dir())
@test !isempty(cache)
end

Expand Down
Loading