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

feat: move getiftversion-to-__init__ #57

Merged
merged 3 commits into from
Aug 18, 2023
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
34 changes: 33 additions & 1 deletion src/IFTPipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,37 @@
include("tracker.jl")
include("h5.jl")

const iftversion = []
function __init__()
function getiftversion()
deps = Pkg.dependencies()
iftversion = []
for (_, dep) in deps
dep.is_direct_dep || continue
dep.version === nothing && continue
dep.name != "IceFloeTracker" && continue
push!(iftversion, dep.version)
break

Check warning on line 34 in src/IFTPipeline.jl

View check run for this annotation

Codecov / codecov/patch

src/IFTPipeline.jl#L33-L34

Added lines #L33 - L34 were not covered by tests
end

# For CI tests where IceFloeTracker is not a dependency
try
ift = iftversion[1]
catch
return "unknown"
end

ift = iftversion[1]
maj = Int(ift.major)
min = Int(ift.minor)
patch = Int(ift.patch)
return "v$maj.$min.$patch"

Check warning on line 48 in src/IFTPipeline.jl

View check run for this annotation

Codecov / codecov/patch

src/IFTPipeline.jl#L44-L48

Added lines #L44 - L48 were not covered by tests
end

push!(iftversion, getiftversion())
return nothing
end

export cache_vector, sharpen,
sharpen_gray,
preprocess,
Expand All @@ -40,7 +71,8 @@
mkclitrack!,
mkfilenames,
makeh5files,
getlatlon
getlatlon,
iftversion

export IceFloeTracker
end
29 changes: 2 additions & 27 deletions src/h5.jl
Original file line number Diff line number Diff line change
@@ -1,28 +1,3 @@
function getiftversion()
deps = Pkg.dependencies()
iftversion = []
for (_, dep) in deps
dep.is_direct_dep || continue
dep.version === nothing && continue
dep.name != "IceFloeTracker" && continue
push!(iftversion, dep.version)
break
end

# For CI tests where IceFloeTracker is not a dependency
try
ift = iftversion[1]
catch
return "unknown"
end

ift = iftversion[1]
maj = Int(ift.major)
min = Int(ift.minor)
patch = Int(ift.patch)
return "v$maj.$min.$patch"
end

"""
makeh5filename(imgfname, ts)

Expand Down Expand Up @@ -125,7 +100,7 @@ The `index` group contains the spatial coordinates in the source image coordinat
function makeh5files(; pathtosampleimg::String, resdir::String)
latlondata = getlatlon(pathtosampleimg)

iftversion = getiftversion()
iftver = iftversion[1]

ptpath = joinpath(resdir, "passtimes.jls")
passtimes = deserialize(ptpath)
Expand Down Expand Up @@ -153,7 +128,7 @@ function makeh5files(; pathtosampleimg::String, resdir::String)
# Add top-level attributes
attrs(file)["fname_reflectance"] = reflectance_refs[i]
attrs(file)["fname_truecolor"] = truecolor_refs[i]
attrs(file)["iftversion"] = iftversion
attrs(file)["iftversion"] = iftver
attrs(file)["crs"] = latlondata["crs"]
attrs(file)["reference"] = "https://doi.org/10.1016/j.rse.2019.111406"
attrs(file)["contact"] = "[email protected]"
Expand Down
4 changes: 2 additions & 2 deletions test/test-h5.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ getcorners(m) = [m[1, 1], m[end, end]]
latcorners = getcorners(latlondata["latitude"])
loncorners = getcorners(latlondata["longitude"])

iftversion = IFTPipeline.getiftversion()
_iftversion = IFTPipeline.iftversion[1]

ptpath = joinpath(resdir, "passtimes.jls")
passtimes = deserialize(ptpath)
Expand Down Expand Up @@ -44,7 +44,7 @@ h5path = joinpath(resdir, "hdf5-files", "20220914T1244.aqua.labeled_image.250m.h
@test typeof(fid) == HDF5.File

# top level attributes
@test attrs(fid)["iftversion"] == iftversion
@test attrs(fid)["iftversion"] == _iftversion
@test attrs(fid)["fname_reflectance"] == reflectance_refs[1]
@test attrs(fid)["fname_truecolor"] == truecolor_refs[1]
@test attrs(fid)["crs"] == latlondata["crs"]
Expand Down
Loading