Skip to content

Commit

Permalink
Add pkgversion function for Julia versions < 1.9
Browse files Browse the repository at this point in the history
  • Loading branch information
lbonaldo committed Jun 21, 2024
1 parent 7df4c46 commit 9d2774d
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/startup/genx_startup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ function __init__()
print_genx_version()
end


function print_genx_version()
v = pkgversion(GenX)
ascii_art = raw""" ____ __ __ _ _
Expand All @@ -15,3 +16,24 @@ function print_genx_version()
println(ascii_art)
return nothing
end


# This function is a workaround for Julia versions < 1.9.
function pkgversion(m::Module)
if VERSION >= v"1.9"
return Base.pkgversion(m)
else
_pkgdir = pkgdir(m)
_pkgdir === nothing && return nothing
project_file = joinpath(_pkgdir, "Project.toml")
isa(project_file, String) && return get_project_version(project_file)
return nothing
end
end

function get_project_version(project_file::String)
d = Base.parsed_toml(project_file)
v = get(d, "version", nothing)
isnothing(v) && return nothing
return VersionNumber(v::AbstractString)
end

0 comments on commit 9d2774d

Please sign in to comment.