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 compiled binaries to get version #997

Merged
merged 3 commits into from
Jan 29, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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 build/libribasim/src/libribasim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions core/src/utils.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
"Get the package version of a given module"
function pkgversion(m::Module)::VersionNumber
version = Base.pkgversion(Ribasim)
if !isnothing(version)
return version
else
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know how the Ribasim team is on this, but to have less nesting you could write it as: !isnothing(version) && return version

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine by me

# 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

Check warning on line 11 in core/src/utils.jl

View check run for this annotation

Codecov / codecov/patch

core/src/utils.jl#L8-L11

Added lines #L8 - L11 were not covered by tests
end
end

"Check that only supported edge types are declared."
function valid_edge_types(db::DB)::Bool
edge_rows = execute(
Expand Down
1 change: 0 additions & 1 deletion python/ribasim_api/tests/test_bmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
Loading