From c2b2f162593fe2c2cfae69de776abd00f3ab4956 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Wed, 31 Jan 2024 21:58:30 +0100 Subject: [PATCH 01/11] Fold create_binaries into root project Just like #1014 --- .github/workflows/core_compat_helper.yml | 2 -- Manifest.toml | 8 +------- Project.toml | 10 +++++++++- build/create_binaries/Project.toml | 21 --------------------- build/create_binaries/build.jl | 9 ++++++++- build/create_binaries/precompile.jl | 2 +- build/ribasim_cli/README.md | 2 +- core/src/main.jl | 1 + docs/src/docs.jl | 4 ---- 9 files changed, 21 insertions(+), 38 deletions(-) delete mode 100644 build/create_binaries/Project.toml delete mode 100644 docs/src/docs.jl diff --git a/.github/workflows/core_compat_helper.yml b/.github/workflows/core_compat_helper.yml index 6db7c8918..5419c932b 100644 --- a/.github/workflows/core_compat_helper.yml +++ b/.github/workflows/core_compat_helper.yml @@ -39,8 +39,6 @@ jobs: import CompatHelper CompatHelper.main(; subdirs=[ "core", - "docs", - "build/create_binaries", "build/libribasim", "build/ribasim_cli" ]) diff --git a/Manifest.toml b/Manifest.toml index f161f91e0..ca3c355ee 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.0" manifest_format = "2.0" -project_hash = "1a68754569dae741c9232c9ae2db3512f52c2b80" +project_hash = "b7b3a6a72e674f9d721af279d67faf1f8110aa05" [[deps.ADTypes]] git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245" @@ -1656,12 +1656,6 @@ git-tree-sha1 = "49ce682769cd5de6c72dcf1b94ed7790cd08974c" uuid = "3161d3a3-bdf6-5164-811a-617609db77b4" version = "1.5.5+0" -[[deps.create_binaries]] -deps = ["Artifacts", "LibGit2", "PackageCompiler", "TOML", "TimeZones"] -path = "build/create_binaries" -uuid = "3cfb6a46-05f0-43df-bb16-bf763deb14b4" -version = "0.1.0" - [[deps.libblastrampoline_jll]] deps = ["Artifacts", "Libdl"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" diff --git a/Project.toml b/Project.toml index ec9276c94..c0bfb53f1 100644 --- a/Project.toml +++ b/Project.toml @@ -4,6 +4,7 @@ description = "Meta-project used to share the Manifest of Ribasim and its depend [deps] Arrow = "69666777-d1a9-59fb-9406-91d4454c9d45" +Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330" Configurations = "5218b696-f38b-4ac9-8b61-a12ec717816d" DataFrames = "a93c6f00-e57d-5684-b7b6-d8193f3e46c0" @@ -16,24 +17,27 @@ Infiltrator = "5903a43b-9cc3-4c30-8d17-598619ec4e9b" InteractiveUtils = "b77e0a4c-d291-57a0-90e8-8db25a27a240" JSON3 = "0f8b85d8-7281-11e9-16c2-39a750bddbf1" Legolas = "741b9549-f6ed-4911-9fbf-4a1c0c97f0cd" +LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" MarkdownTables = "1862ce21-31c7-451e-824c-f20fa3f90fa2" MetaGraphsNext = "fa8bd995-216d-47f1-8a91-f3b68fbeb377" OrderedCollections = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" ReTestItems = "817f1d60-ba6b-4fd5-9520-3cf149f6a823" Revise = "295af30f-e4ad-537b-8983-00126c2a3abe" Ribasim = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635" SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" +TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" -create_binaries = "3cfb6a46-05f0-43df-bb16-bf763deb14b4" libribasim = "f319f290-633d-4573-adfe-d6d5548b6388" ribasim_cli = "e45c999e-e944-4589-a8e6-7d0b7a60140a" [compat] +Artifacts = "<0.0.1,1" Configurations = "0.17" DataFrames = "1" Dates = "<0.0.1,1" @@ -43,7 +47,11 @@ IJulia = "1" InteractiveUtils = "<0.0.1,1" JSON3 = "1.12" Legolas = "0.5" +LibGit2 = "<0.0.1,1" Logging = "<0.0.1,1" MarkdownTables = "1" OrderedCollections = "1.6" +PackageCompiler = "2" +TimeZones = "=1.14.0, 1" +TOML = "<0.0.1,1" julia = "1.10" diff --git a/build/create_binaries/Project.toml b/build/create_binaries/Project.toml deleted file mode 100644 index aef92c80d..000000000 --- a/build/create_binaries/Project.toml +++ /dev/null @@ -1,21 +0,0 @@ -name = "create_binaries" -uuid = "3cfb6a46-05f0-43df-bb16-bf763deb14b4" -authors = ["Deltares and contributors "] -description = "Build Ribasim binaries with PackageCompiler" -manifest = "../../Manifest.toml" -version = "0.1.0" - -[deps] -Artifacts = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" -LibGit2 = "76f85450-5226-5b5a-8eaa-529ad045b433" -PackageCompiler = "9b87118b-4619-50d2-8e1e-99f35a4d4d9d" -TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" - -[compat] -Artifacts = "<0.0.1,1" -LibGit2 = "<0.0.1,1" -PackageCompiler = "2" -TOML = "<0.0.1,1" -TimeZones = "=1.14.0, 1" -julia = "1.10" diff --git a/build/create_binaries/build.jl b/build/create_binaries/build.jl index 9c27c6e84..f19181825 100644 --- a/build/create_binaries/build.jl +++ b/build/create_binaries/build.jl @@ -1,4 +1,11 @@ -using create_binaries +using Artifacts +using PackageCompiler +using TOML +using LibGit2 + +include("src/add_metadata.jl") +include("src/create_app.jl") +include("src/create_lib.jl") """ Build the Ribasim CLI, libribasim, or both, using PackageCompiler. diff --git a/build/create_binaries/precompile.jl b/build/create_binaries/precompile.jl index 73cd6c6f2..098e14760 100644 --- a/build/create_binaries/precompile.jl +++ b/build/create_binaries/precompile.jl @@ -4,4 +4,4 @@ using Ribasim, Dates, TOML toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml") -Ribasim.run(toml_path) +Ribasim.main(toml_path) diff --git a/build/ribasim_cli/README.md b/build/ribasim_cli/README.md index b51c5e27f..bc046000c 100644 --- a/build/ribasim_cli/README.md +++ b/build/ribasim_cli/README.md @@ -13,7 +13,7 @@ If you have installed Julia and Ribasim, a simulation can also be started from t line as follows: ``` -julia --eval 'using Ribasim; Ribasim.run("path/to/model/ribasim.toml")' +julia --eval 'using Ribasim; Ribasim.main("path/to/model/ribasim.toml")' ``` With a Ribasim CLI build this becomes: diff --git a/core/src/main.jl b/core/src/main.jl index fb621c0e9..3a02608e3 100644 --- a/core/src/main.jl +++ b/core/src/main.jl @@ -8,6 +8,7 @@ main(toml_path::AbstractString)::Cint = main([toml_path]) """ main(ARGS::Vector{String})::Cint + This is the main entry point of the application. Performs argument parsing and sets up logging for both terminal and file. Calls Ribasim.run() and handles exceptions to convert to exit codes. diff --git a/docs/src/docs.jl b/docs/src/docs.jl deleted file mode 100644 index 12701a5c9..000000000 --- a/docs/src/docs.jl +++ /dev/null @@ -1,4 +0,0 @@ -__precompile__(false) - -# This is not really a package, but needs to be set up like one so we can run -# `dev build/create_binaries` from the root project. From 92eddaadc40dd66915b200278378286120eed273 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Wed, 31 Jan 2024 22:25:46 +0100 Subject: [PATCH 02/11] Fold ribasim_cli into root project Easy to do since ribasim_cli is a thin wrapper over Ribasim.main nowadays. --- .github/workflows/core_compat_helper.yml | 1 - .gitignore | 2 +- .../Ribasim_Linux_TestRibasimCli.xml | 2 +- .../Ribasim_Windows_TestRibasimCli.xml | 2 +- Manifest.toml | 8 +---- Project.toml | 5 ++-- build/create_binaries/precompile.jl | 2 +- build/create_binaries/src/create_app.jl | 30 +++++++++++++++++-- .../tests/test_models.py | 0 build/ribasim_cli/Project.toml | 21 ------------- build/ribasim_cli/README.md | 23 -------------- build/ribasim_cli/src/ribasim_cli.jl | 7 ----- pixi.toml | 2 +- 13 files changed, 36 insertions(+), 69 deletions(-) rename build/{ribasim_cli => create_binaries}/tests/test_models.py (100%) delete mode 100644 build/ribasim_cli/Project.toml delete mode 100644 build/ribasim_cli/README.md delete mode 100644 build/ribasim_cli/src/ribasim_cli.jl diff --git a/.github/workflows/core_compat_helper.yml b/.github/workflows/core_compat_helper.yml index 5419c932b..02012b2e3 100644 --- a/.github/workflows/core_compat_helper.yml +++ b/.github/workflows/core_compat_helper.yml @@ -40,7 +40,6 @@ jobs: CompatHelper.main(; subdirs=[ "core", "build/libribasim", - "build/ribasim_cli" ]) shell: julia --color=yes {0} env: diff --git a/.gitignore b/.gitignore index 56a0cdec8..13448e806 100644 --- a/.gitignore +++ b/.gitignore @@ -147,7 +147,7 @@ dmypy.json .pyre/ /.luarc.json -build/ribasim_cli/tests/temp/ +build/create_binaries/tests/temp/ python/ribasim_api/tests/temp/ report.xml /utils/juliaup diff --git a/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_TestRibasimCli.xml b/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_TestRibasimCli.xml index 2fd093858..7e755283f 100644 --- a/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_TestRibasimCli.xml +++ b/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_TestRibasimCli.xml @@ -4,7 +4,7 @@ - diff --git a/.teamcity/Ribasim_Windows/buildTypes/Ribasim_Windows_TestRibasimCli.xml b/.teamcity/Ribasim_Windows/buildTypes/Ribasim_Windows_TestRibasimCli.xml index 67dd0f46f..65a181e6c 100644 --- a/.teamcity/Ribasim_Windows/buildTypes/Ribasim_Windows_TestRibasimCli.xml +++ b/.teamcity/Ribasim_Windows/buildTypes/Ribasim_Windows_TestRibasimCli.xml @@ -4,7 +4,7 @@ - diff --git a/Manifest.toml b/Manifest.toml index ca3c355ee..bab0cfb57 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.0" manifest_format = "2.0" -project_hash = "b7b3a6a72e674f9d721af279d67faf1f8110aa05" +project_hash = "6fe4cbe89d85dfdb47577a7dbbb0ab70f3d1a748" [[deps.ADTypes]] git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245" @@ -1682,9 +1682,3 @@ version = "1.52.0+1" deps = ["Artifacts", "Libdl"] uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" version = "17.4.0+2" - -[[deps.ribasim_cli]] -deps = ["Dates", "Logging", "Ribasim", "SciMLBase", "TOML", "TerminalLoggers"] -path = "build/ribasim_cli" -uuid = "e45c999e-e944-4589-a8e6-7d0b7a60140a" -version = "0.1.0" diff --git a/Project.toml b/Project.toml index c0bfb53f1..7ab0ee8f1 100644 --- a/Project.toml +++ b/Project.toml @@ -31,10 +31,10 @@ SQLite = "0aa819cd-b072-5ff4-a722-6bc24af294d9" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" +TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" libribasim = "f319f290-633d-4573-adfe-d6d5548b6388" -ribasim_cli = "e45c999e-e944-4589-a8e6-7d0b7a60140a" [compat] Artifacts = "<0.0.1,1" @@ -52,6 +52,7 @@ Logging = "<0.0.1,1" MarkdownTables = "1" OrderedCollections = "1.6" PackageCompiler = "2" -TimeZones = "=1.14.0, 1" TOML = "<0.0.1,1" +TerminalLoggers = "0.1.7" +TimeZones = "=1.14.0, 1" julia = "1.10" diff --git a/build/create_binaries/precompile.jl b/build/create_binaries/precompile.jl index 098e14760..b12cc0ce8 100644 --- a/build/create_binaries/precompile.jl +++ b/build/create_binaries/precompile.jl @@ -1,7 +1,7 @@ # Workflow that will compile a lot of the code we will need. # With the purpose of reducing the latency for compiled binaries. -using Ribasim, Dates, TOML +using Ribasim toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml") Ribasim.main(toml_path) diff --git a/build/create_binaries/src/create_app.jl b/build/create_binaries/src/create_app.jl index 056dc5b7b..a7bae95f2 100644 --- a/build/create_binaries/src/create_app.jl +++ b/build/create_binaries/src/create_app.jl @@ -1,6 +1,30 @@ -"Build the Ribasim CLI using PackageCompiler" +""" + build_app() + +Build the Ribasim CLI using PackageCompiler. + +This builds the `main` function from the Ribasim Julia package into a command line interface +(cli) application using PackageCompiler.jl. + +This enables using Ribasim without having to install Julia, and thus makes it more +convenient to use in certain settings where installation must be simple and no interactive +Julia session is needed. + +If you have installed Julia and Ribasim, a simulation can also be started from the command +line as follows: + +``` +julia --eval 'using Ribasim; Ribasim.main("path/to/model/ribasim.toml")' +``` + +With a Ribasim CLI build this becomes: + +``` +ribasim path/to/model/ribasim.toml +``` +""" function build_app() - project_dir = "../ribasim_cli" + project_dir = "../../core" license_file = "../../LICENSE" output_dir = "ribasim_cli" git_repo = "../.." @@ -9,7 +33,7 @@ function build_app() project_dir, output_dir; # map from binary name to julia function name - executables = ["ribasim" => "julia_main"], + executables = ["ribasim" => "main"], precompile_execution_file = "precompile.jl", include_lazy_artifacts = true, force = true, diff --git a/build/ribasim_cli/tests/test_models.py b/build/create_binaries/tests/test_models.py similarity index 100% rename from build/ribasim_cli/tests/test_models.py rename to build/create_binaries/tests/test_models.py diff --git a/build/ribasim_cli/Project.toml b/build/ribasim_cli/Project.toml deleted file mode 100644 index 728a085ca..000000000 --- a/build/ribasim_cli/Project.toml +++ /dev/null @@ -1,21 +0,0 @@ -name = "ribasim_cli" -uuid = "e45c999e-e944-4589-a8e6-7d0b7a60140a" -authors = ["Deltares and contributors "] -manifest = "../../Manifest.toml" -version = "0.1.0" - -[deps] -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" -Ribasim = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635" -SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" -TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" -TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" - -[compat] -Dates = "<0.0.1,1" -Logging = "<0.0.1,1" -SciMLBase = "1.60, 2" -TOML = "<0.0.1,1" -TerminalLoggers = "0.1.7" -julia = "1.10" diff --git a/build/ribasim_cli/README.md b/build/ribasim_cli/README.md deleted file mode 100644 index bc046000c..000000000 --- a/build/ribasim_cli/README.md +++ /dev/null @@ -1,23 +0,0 @@ -# Ribasim CLI - -This is a [Julia](https://julialang.org/) project that uses the -[Ribasim](https://github.com/Deltares/Ribasim) Julia package, puts a simple command line -interface (cli) on top, and packages this into a standalone application using -[PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl). - -This enables using Ribasim without having to install Julia, and thus makes it more -convenient to use in certain settings where installation must be simple and no interactive -Julia session is needed. - -If you have installed Julia and Ribasim, a simulation can also be started from the command -line as follows: - -``` -julia --eval 'using Ribasim; Ribasim.main("path/to/model/ribasim.toml")' -``` - -With a Ribasim CLI build this becomes: - -``` -ribasim path/to/model/ribasim.toml -``` diff --git a/build/ribasim_cli/src/ribasim_cli.jl b/build/ribasim_cli/src/ribasim_cli.jl deleted file mode 100644 index 6e28f8507..000000000 --- a/build/ribasim_cli/src/ribasim_cli.jl +++ /dev/null @@ -1,7 +0,0 @@ -module ribasim_cli - -using Ribasim - -julia_main()::Cint = Ribasim.main(ARGS) - -end # module diff --git a/pixi.toml b/pixi.toml index fe84712ae..06a6032b7 100644 --- a/pixi.toml +++ b/pixi.toml @@ -78,7 +78,7 @@ remove-artifacts = "julia --eval 'rm(joinpath(Base.DEPOT_PATH[1], \"artifacts\") # Test test-ribasim-python = "pytest --numprocesses=4 python/ribasim/tests" test-ribasim-api = "pytest --basetemp=python/ribasim_api/tests/temp --junitxml=report.xml python/ribasim_api/tests" -test-ribasim-cli = "pytest --numprocesses=4 --basetemp=build/ribasim_cli/tests/temp --junitxml=report.xml build/ribasim_cli/tests" +test-ribasim-cli = "pytest --numprocesses=4 --basetemp=build/create_binaries/tests/temp --junitxml=report.xml build/create_binaries/tests" test-ribasim-core = { cmd = "julia --project=core --eval 'using Pkg; Pkg.test()'", depends_on = [ "generate-testmodels", ] } From be64b6b0aaffdf4bb287c3a315d88d20a07682d7 Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Wed, 31 Jan 2024 22:50:15 +0100 Subject: [PATCH 03/11] Fold libribasim into core project --- .github/workflows/core_compat_helper.yml | 2 +- Manifest.toml | 8 +--- Project.toml | 2 +- build/create_binaries/src/create_lib.jl | 39 +++++++++++++++++++- build/libribasim/Project.toml | 17 --------- build/libribasim/README.md | 32 ---------------- core/src/Ribasim.jl | 3 ++ {build/libribasim => core}/src/libribasim.jl | 2 +- core/test/libribasim_test.jl | 4 -- 9 files changed, 44 insertions(+), 65 deletions(-) delete mode 100644 build/libribasim/Project.toml delete mode 100644 build/libribasim/README.md rename {build/libribasim => core}/src/libribasim.jl (99%) diff --git a/.github/workflows/core_compat_helper.yml b/.github/workflows/core_compat_helper.yml index 02012b2e3..c2e96be0f 100644 --- a/.github/workflows/core_compat_helper.yml +++ b/.github/workflows/core_compat_helper.yml @@ -38,8 +38,8 @@ jobs: run: | import CompatHelper CompatHelper.main(; subdirs=[ + ".", "core", - "build/libribasim", ]) shell: julia --color=yes {0} env: diff --git a/Manifest.toml b/Manifest.toml index bab0cfb57..e21c6740c 100644 --- a/Manifest.toml +++ b/Manifest.toml @@ -2,7 +2,7 @@ julia_version = "1.10.0" manifest_format = "2.0" -project_hash = "6fe4cbe89d85dfdb47577a7dbbb0ab70f3d1a748" +project_hash = "504636556d0ad5642b24c3c7f1c1471337cf93ca" [[deps.ADTypes]] git-tree-sha1 = "41c37aa88889c171f1300ceac1313c06e891d245" @@ -1661,12 +1661,6 @@ deps = ["Artifacts", "Libdl"] uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" version = "5.8.0+1" -[[deps.libribasim]] -deps = ["BasicModelInterface", "Dates", "Ribasim", "TOML"] -path = "build/libribasim" -uuid = "f319f290-633d-4573-adfe-d6d5548b6388" -version = "0.1.0" - [[deps.libsodium_jll]] deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] git-tree-sha1 = "848ab3d00fe39d6fbc2a8641048f8f272af1c51e" diff --git a/Project.toml b/Project.toml index 7ab0ee8f1..5a23c8954 100644 --- a/Project.toml +++ b/Project.toml @@ -34,10 +34,10 @@ Tables = "bd369af6-aec1-5ad0-b16a-f7cc5008161c" TerminalLoggers = "5d786b92-1e48-4d6f-9151-6b4477ca9bed" TestEnv = "1e6cf692-eddd-4d53-88a5-2d735e33781b" TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53" -libribasim = "f319f290-633d-4573-adfe-d6d5548b6388" [compat] Artifacts = "<0.0.1,1" +BasicModelInterface = "0.1" Configurations = "0.17" DataFrames = "1" Dates = "<0.0.1,1" diff --git a/build/create_binaries/src/create_lib.jl b/build/create_binaries/src/create_lib.jl index 8e8b01a31..104a648f1 100644 --- a/build/create_binaries/src/create_lib.jl +++ b/build/create_binaries/src/create_lib.jl @@ -1,6 +1,41 @@ -"Build libribasim using PackageCompiler" +""" + build_lib() + +Build libribasim using PackageCompiler + +Libribasim is a shared library that exposes Ribasim functionality to external (non-Julian) +programs. It can be compiled using [PackageCompiler's +create_lib](https://julialang.github.io/PackageCompiler.jl/stable/libs.html), which is set +up in this directory. The C API that is offered to control Ribasim is the C API of the [Basic +Model Interface](https://bmi.readthedocs.io/en/latest/), also known as BMI. + +Not all BMI functions are implemented yet, this has been set up as a proof of concept to +demonstrate that we can use other software such as +[`imod_coupler`](https://github.com/Deltares/imod_coupler) to control Ribasim and couple it to +other models. + +Here is an example of using libribasim from Python: + +```python +In [1]: from ctypes import CDLL, c_int, c_char_p, create_string_buffer, byref + +In [2]: c_dll = CDLL("libribasim", winmode=0x08) # winmode for Windows + +In [3]: argument = create_string_buffer(0) + ...: c_dll.init_julia(c_int(0), byref(argument)) +Out[3]: 1 + +In [4]: config_path = "ribasim.toml" + +In [5]: c_dll.initialize(c_char_p(config_path.encode())) +Out[5]: 0 + +In [6]: c_dll.update() +Out[6]: 0 +``` +""" function build_lib() - project_dir = "../libribasim" + project_dir = "../../core" license_file = "../../LICENSE" output_dir = "libribasim" git_repo = "../.." diff --git a/build/libribasim/Project.toml b/build/libribasim/Project.toml deleted file mode 100644 index 2b7700197..000000000 --- a/build/libribasim/Project.toml +++ /dev/null @@ -1,17 +0,0 @@ -name = "libribasim" -uuid = "f319f290-633d-4573-adfe-d6d5548b6388" -authors = ["Deltares and contributors "] -manifest = "../../Manifest.toml" -version = "0.1.0" - -[deps] -BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330" -Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" -Ribasim = "aac5e3d9-0b8f-4d4f-8241-b1a7a9632635" -TOML = "fa267f1f-6049-4f14-aa54-33bafae1ed76" - -[compat] -BasicModelInterface = "0.1" -Dates = "<0.0.1,1" -TOML = "<0.0.1,1" -julia = "1.10" diff --git a/build/libribasim/README.md b/build/libribasim/README.md deleted file mode 100644 index 5906696a7..000000000 --- a/build/libribasim/README.md +++ /dev/null @@ -1,32 +0,0 @@ -# Libribasim - -Libribasim is a shared library that exposes Ribasim functionality to external (non-Julian) -programs. It can be compiled using [PackageCompiler's -create_lib](https://julialang.github.io/PackageCompiler.jl/stable/libs.html) , which is set -up in this directory. The C API that is offered to control Ribasim is the C API of the [Basic -Model Interface](https://bmi.readthedocs.io/en/latest/), also known as BMI. - -Not all BMI functions are implemented yet, this has been set up as a proof of concept to -demonstrate that we could use other software such as -[`imod_coupler`](https://github.com/Deltares/imod_coupler) to control Ribasim and couple it to -other models. - -Here is an example of using libribasim from Python: - -```python -In [1]: from ctypes import CDLL, c_int, c_char_p, create_string_buffer, byref - -In [2]: c_dll = CDLL("libribasim", winmode=0x08) # winmode for Windows - -In [3]: argument = create_string_buffer(0) - ...: c_dll.init_julia(c_int(0), byref(argument)) -Out[3]: 1 - -In [4]: config_path = "ribasim.toml" - -In [5]: c_dll.initialize(c_char_p(config_path.encode())) -Out[5]: 0 - -In [6]: c_dll.update() -Out[6]: 0 -``` diff --git a/core/src/Ribasim.jl b/core/src/Ribasim.jl index 79947b8a6..d98d5a609 100644 --- a/core/src/Ribasim.jl +++ b/core/src/Ribasim.jl @@ -68,6 +68,8 @@ using Tables: Tables, AbstractRow, columntable, getcolumn using TerminalLoggers: TerminalLogger using TimerOutputs +export libribasim + const to = TimerOutput() TimerOutputs.complement!() @@ -84,5 +86,6 @@ include("create.jl") include("bmi.jl") include("consts.jl") include("main.jl") +include("libribasim.jl") end # module Ribasim diff --git a/build/libribasim/src/libribasim.jl b/core/src/libribasim.jl similarity index 99% rename from build/libribasim/src/libribasim.jl rename to core/src/libribasim.jl index 448d68d02..e8af88f50 100644 --- a/build/libribasim/src/libribasim.jl +++ b/core/src/libribasim.jl @@ -1,7 +1,7 @@ module libribasim import BasicModelInterface as BMI -using Ribasim +import ..Ribasim # globals model::Union{Ribasim.Model, Nothing} = nothing diff --git a/core/test/libribasim_test.jl b/core/test/libribasim_test.jl index 3bcac1fc0..1eb42f431 100644 --- a/core/test/libribasim_test.jl +++ b/core/test/libribasim_test.jl @@ -1,8 +1,4 @@ @testitem "libribasim" begin - import BasicModelInterface as BMI - - include("../../build/libribasim/src/libribasim.jl") - toml_path = normpath(@__DIR__, "../../generated_testmodels/basic/ribasim.toml") # data from which we create pointers for libribasim From 3de55da43a2e718c4af79ff866237fbe826fe72e Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Wed, 31 Jan 2024 22:53:25 +0100 Subject: [PATCH 04/11] Remove create_binaries and move contents up --- build/{create_binaries => }/README.md | 0 build/{create_binaries => }/build.jl | 0 build/{create_binaries => }/precompile.jl | 0 build/{create_binaries => }/src/add_metadata.jl | 0 build/{create_binaries => }/src/create_app.jl | 0 build/{create_binaries => }/src/create_binaries.jl | 0 build/{create_binaries => }/src/create_lib.jl | 0 build/{create_binaries => }/tests/test_models.py | 0 8 files changed, 0 insertions(+), 0 deletions(-) rename build/{create_binaries => }/README.md (100%) rename build/{create_binaries => }/build.jl (100%) rename build/{create_binaries => }/precompile.jl (100%) rename build/{create_binaries => }/src/add_metadata.jl (100%) rename build/{create_binaries => }/src/create_app.jl (100%) rename build/{create_binaries => }/src/create_binaries.jl (100%) rename build/{create_binaries => }/src/create_lib.jl (100%) rename build/{create_binaries => }/tests/test_models.py (100%) diff --git a/build/create_binaries/README.md b/build/README.md similarity index 100% rename from build/create_binaries/README.md rename to build/README.md diff --git a/build/create_binaries/build.jl b/build/build.jl similarity index 100% rename from build/create_binaries/build.jl rename to build/build.jl diff --git a/build/create_binaries/precompile.jl b/build/precompile.jl similarity index 100% rename from build/create_binaries/precompile.jl rename to build/precompile.jl diff --git a/build/create_binaries/src/add_metadata.jl b/build/src/add_metadata.jl similarity index 100% rename from build/create_binaries/src/add_metadata.jl rename to build/src/add_metadata.jl diff --git a/build/create_binaries/src/create_app.jl b/build/src/create_app.jl similarity index 100% rename from build/create_binaries/src/create_app.jl rename to build/src/create_app.jl diff --git a/build/create_binaries/src/create_binaries.jl b/build/src/create_binaries.jl similarity index 100% rename from build/create_binaries/src/create_binaries.jl rename to build/src/create_binaries.jl diff --git a/build/create_binaries/src/create_lib.jl b/build/src/create_lib.jl similarity index 100% rename from build/create_binaries/src/create_lib.jl rename to build/src/create_lib.jl diff --git a/build/create_binaries/tests/test_models.py b/build/tests/test_models.py similarity index 100% rename from build/create_binaries/tests/test_models.py rename to build/tests/test_models.py From 462cb0314856f626110239a78da678ef4452d5bf Mon Sep 17 00:00:00 2001 From: Martijn Visser Date: Wed, 31 Jan 2024 23:02:38 +0100 Subject: [PATCH 05/11] Update paths for create_binaries move --- .gitignore | 6 +++--- .../buildTypes/Ribasim_Linux_BuildLibribasim.xml | 2 +- .../buildTypes/Ribasim_Linux_BuildRibasimCli.xml | 4 ++-- .../buildTypes/Ribasim_Linux_TestRibasimApi.xml | 2 +- .../buildTypes/Ribasim_Linux_TestRibasimCli.xml | 4 ++-- .../buildTypes/Ribasim_Windows_BuildLibribasim.xml | 2 +- .../buildTypes/Ribasim_Windows_BuildRibasimCli.xml | 4 ++-- .../buildTypes/Ribasim_Windows_TestRibasimApi.xml | 2 +- .../buildTypes/Ribasim_Windows_TestRibasimCli.xml | 4 ++-- build/src/create_app.jl | 6 +++--- build/src/create_binaries.jl | 14 -------------- build/src/create_lib.jl | 6 +++--- build/tests/test_models.py | 8 +------- pixi.toml | 8 ++++---- python/ribasim_api/tests/conftest.py | 2 +- 15 files changed, 27 insertions(+), 47 deletions(-) delete mode 100644 build/src/create_binaries.jl diff --git a/.gitignore b/.gitignore index 13448e806..7b5586e8c 100644 --- a/.gitignore +++ b/.gitignore @@ -10,8 +10,8 @@ docs/build/ docs/site/ /generated_testmodels -build/create_binaries/ribasim_cli/ -build/create_binaries/libribasim/ +build/ribasim_cli/ +build/libribasim/ JuliaSysimage.dll LocalPreferences.toml @@ -147,7 +147,7 @@ dmypy.json .pyre/ /.luarc.json -build/create_binaries/tests/temp/ +build/tests/temp/ python/ribasim_api/tests/temp/ report.xml /utils/juliaup diff --git a/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_BuildLibribasim.xml b/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_BuildLibribasim.xml index 21460aa82..772278a6d 100644 --- a/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_BuildLibribasim.xml +++ b/.teamcity/Ribasim_Linux/buildTypes/Ribasim_Linux_BuildLibribasim.xml @@ -4,7 +4,7 @@ -