From 1787fc0b2398f914c9ab67984976c45f8de1a63d Mon Sep 17 00:00:00 2001 From: Hofer-Julian Date: Mon, 29 Jan 2024 11:12:51 +0100 Subject: [PATCH 1/3] Allow compiled binaries to get version We started using the function that julia provides, but it doesn't seem to work with compiled binaries Fixes #364 --- build/libribasim/src/libribasim.jl | 2 +- core/src/utils.jl | 8 ++++++++ python/ribasim_api/tests/test_bmi.py | 1 - 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/build/libribasim/src/libribasim.jl b/build/libribasim/src/libribasim.jl index ee216288f..448d68d02 100644 --- a/build/libribasim/src/libribasim.jl +++ b/build/libribasim/src/libribasim.jl @@ -175,7 +175,7 @@ end Base.@ccallable function get_version(version::Cstring)::Cint @try_c_uninitialized begin - ribasim_version = pkgversion(Ribasim) + ribasim_version = Ribasim.pkgversion(Ribasim) unsafe_write_to_cstring!(version, string(ribasim_version)) end end diff --git a/core/src/utils.jl b/core/src/utils.jl index 5ca7608b4..34236c8aa 100644 --- a/core/src/utils.jl +++ b/core/src/utils.jl @@ -1,3 +1,11 @@ +"Get the package version of a given module" +function pkgversion(m::Module)::VersionNumber + rootmodule = Base.moduleroot(m) + pkg = Base.PkgId(rootmodule) + pkgorigin = get(Base.pkgorigins, pkg, nothing) + return pkgorigin.version +end + "Check that only supported edge types are declared." function valid_edge_types(db::DB)::Bool edge_rows = execute( diff --git a/python/ribasim_api/tests/test_bmi.py b/python/ribasim_api/tests/test_bmi.py index 01342a274..9d8664d6d 100644 --- a/python/ribasim_api/tests/test_bmi.py +++ b/python/ribasim_api/tests/test_bmi.py @@ -126,7 +126,6 @@ def test_get_component_name(libribasim): assert libribasim.get_component_name() == "Ribasim" -@pytest.mark.skip("https://github.com/Deltares/Ribasim/issues/364") def test_get_version(libribasim): toml_path = Path(__file__).parents[3] / "core" / "Project.toml" with open(toml_path, mode="rb") as fp: From 036d3165a2aea0e805f0ad647b537e46adda039f Mon Sep 17 00:00:00 2001 From: Hofer-Julian Date: Mon, 29 Jan 2024 12:54:06 +0100 Subject: [PATCH 2/3] Try `Base.pkgversion` first before using our vendored implementation --- core/src/utils.jl | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/core/src/utils.jl b/core/src/utils.jl index 34236c8aa..67450ee53 100644 --- a/core/src/utils.jl +++ b/core/src/utils.jl @@ -1,9 +1,15 @@ "Get the package version of a given module" function pkgversion(m::Module)::VersionNumber - rootmodule = Base.moduleroot(m) - pkg = Base.PkgId(rootmodule) - pkgorigin = get(Base.pkgorigins, pkg, nothing) - return pkgorigin.version + version = Base.pkgversion(Ribasim) + if !isnothing(version) + return version + else + # Base.pkgversion doesn't work with compiled binaries + rootmodule = Base.moduleroot(m) + pkg = Base.PkgId(rootmodule) + pkgorigin = get(Base.pkgorigins, pkg, nothing) + return pkgorigin.version + end end "Check that only supported edge types are declared." From da787fdf312bbfde20179e889973f5de32528fe7 Mon Sep 17 00:00:00 2001 From: Hofer-Julian Date: Mon, 29 Jan 2024 13:25:25 +0100 Subject: [PATCH 3/3] Address Marnix' comment --- core/src/utils.jl | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/core/src/utils.jl b/core/src/utils.jl index 67450ee53..daeb1ca00 100644 --- a/core/src/utils.jl +++ b/core/src/utils.jl @@ -1,15 +1,14 @@ "Get the package version of a given module" function pkgversion(m::Module)::VersionNumber version = Base.pkgversion(Ribasim) - if !isnothing(version) - return version - else - # Base.pkgversion doesn't work with compiled binaries - rootmodule = Base.moduleroot(m) - pkg = Base.PkgId(rootmodule) - pkgorigin = get(Base.pkgorigins, pkg, nothing) - return pkgorigin.version - end + !isnothing(version) && return version + + # Base.pkgversion doesn't work with compiled binaries + # If it returns `nothing`, we try a different way + rootmodule = Base.moduleroot(m) + pkg = Base.PkgId(rootmodule) + pkgorigin = get(Base.pkgorigins, pkg, nothing) + return pkgorigin.version end "Check that only supported edge types are declared."