Skip to content

Commit

Permalink
Merge pull request #15 from eWaterCycle/julia-tests
Browse files Browse the repository at this point in the history
Add tests for RemoteBmi.jl
  • Loading branch information
sverhoeven authored Nov 7, 2024
2 parents 275155f + 67943e8 commit a4ad77c
Show file tree
Hide file tree
Showing 88 changed files with 5,334 additions and 2,024 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ on:
required: false
type: boolean
default: false
secrets:
codecov_token:
required: true

permissions:
id-token: write # This is required for requesting the JWT

jobs:
test:
Expand All @@ -39,14 +39,21 @@ jobs:
with:
version: ${{ inputs.version }}
arch: ${{ inputs.arch }}
project: './RemoteBMI.jl'
- name: Use Julia cache
uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@v1
with:
project: './RemoteBMI.jl'
- uses: julia-actions/julia-runtest@v1
with:
project: './RemoteBMI.jl'
- uses: julia-actions/julia-processcoverage@v1
if: ${{ inputs.run_codecov }}
if: ${{ inputs.run_codecov }}
with:
directories: "RemoteBMI.jl/src"
- uses: codecov/codecov-action@v4
if: ${{ inputs.run_codecov }}
with:
file: lcov.info
token: ${{ secrets.codecov_token }}
use_oidc: true
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
name: Test on PRs
name: Julia test on PRs

on:
pull_request:
branches:
- main
# branches:
# - main
paths:
- "src/**"
- "test/**"
- "*.toml"
- "RemoteBMI.jl/src/**"
- "RemoteBMI.jl/test/**"
- "RemoteBMI.jl/*.toml"
types: [opened, synchronize, reopened]

concurrency:
Expand All @@ -18,12 +18,10 @@ concurrency:

jobs:
test:
uses: ./.github/workflows/ReusableTest.yml
uses: ./.github/workflows/JuliaReusableTest.yml
with:
os: ubuntu-latest
version: "1"
arch: x64
allow_failure: false
run_codecov: true
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
Original file line number Diff line number Diff line change
@@ -1,35 +1,32 @@
name: Test
name: Julia test

on:
push:
branches:
- main
tags: ["*"]

paths:
- "RemoteBMI.jl/**"
- .github/workflows/julia-test.yml
workflow_dispatch:

jobs:
test:
uses: ./.github/workflows/ReusableTest.yml
uses: ./.github/workflows/JuliaReusableTest.yml
with:
os: ${{ matrix.os }}
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
allow_failure: ${{ matrix.allow_failure }}
run_codecov: ${{ matrix.version == '1' && matrix.os == 'ubuntu-latest' }}
secrets:
codecov_token: ${{ secrets.CODECOV_TOKEN }}
strategy:
fail-fast: false
matrix:
version:
- "1.6"
- "lts"
- "1"
os:
- ubuntu-latest
#- macOS-latest
#- windows-latest
arch:
- x64
allow_failure: [false]

20 changes: 18 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Remote BMI

[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![Codecov test coverage](https://codecov.io/gh/eWaterCycle/remotebmi/graph/badge.svg)](https://app.codecov.io/gh/eWaterCycle/remotebmi)

The [Basic Model Interface (BMI)](https://bmi.readthedocs.io/en/stable/) is a standard interface for models.
Expand All @@ -21,6 +22,12 @@ The [REST API specification](openapi.yaml) is in the [OpenAPI](https://swagger.i

[OpenAPI reference documentation](https://redocly.github.io/redoc/?url=https://github.com/eWaterCycle/remotebmi/raw/main/openapi.yaml)

## Structure

This repository is a monorepo containing packages for different languages.
1. Python client and server, in [./python/](./python) directory
2. Julia server, in [./RemoteBMI.jl/](./RemoteBMI.jl/) directory

### Python consumer

Installation
Expand Down Expand Up @@ -94,10 +101,19 @@ Given you have a model class called `MyModel` and a BMI called `BMI` inside the

```julia
using MyPackage
using RemoteBMI
import RemoteBMI.Server: run_bmi_server

port = parse(Int, get(ENV, "BMI_PORT", "50051"))
RemoteBMI.run(MyPackage.Model, "0.0.0.0", port)
run_bmi_server(MyPackage.Model, "0.0.0.0", port)
```

### Julia consumer

```julia
import RemoteBMI.Client: BMIClient
import BasicModelInterface as BMI
model = BMIClient("http://localhost:50555")
BMI.get_component_name(m)
```

### R provider
Expand Down
10 changes: 9 additions & 1 deletion RemoteBMI.jl/.editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,14 @@ root = true
end_of_line = lf
insert_final_newline = true
charset = utf-8
indent_size = 2
indent_style = space
trim_trailing_whitespace = true

[*.jl]
indent_size = 4

[*.md]
indent_size = 2

[*.{yml,toml,json}]
indent_size = 2
2 changes: 1 addition & 1 deletion RemoteBMI.jl/.github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!--
Thanks for making a pull request to RemoteBMI.jl.
We have added this PR template to help you help us.
Make sure to read the contributing guidelines and abide to the code of conduct.
Make sure to read the contributing guidelines and abide by the code of conduct.
See the comments below, fill the required fields, and check the items.
-->

Expand Down
10 changes: 7 additions & 3 deletions RemoteBMI.jl/.github/workflows/Docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,23 @@ jobs:
version: "1"
- name: Use Julia cache
uses: julia-actions/cache@v2
- run: |
- name: Instantiate environment with development version of the package
run: |
julia --project=docs -e '
using Pkg
Pkg.develop(PackageSpec(path=pwd()))
Pkg.instantiate()'
- run: |
- name: Run doctest
run: |
julia --project=docs -e '
using Documenter: DocMeta, doctest
using RemoteBMI
DocMeta.setdocmeta!(RemoteBMI, :DocTestSetup, :(using RemoteBMI); recursive=true)
doctest(RemoteBMI)'
- run: julia --project=docs docs/make.jl
- name: Generate and deploy documentation
run: julia --project=docs docs/make.jl
env:
JULIA_PKG_SERVER: ""
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
DOCUMENTER_KEY: ${{ secrets.DOCUMENTER_KEY }}
GKSwstype: "100" # https://discourse.julialang.org/t/generation-of-documentation-fails-qt-qpa-xcb-could-not-connect-to-display/60988
7 changes: 6 additions & 1 deletion RemoteBMI.jl/.gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
*.jl.*.cov
*.jl.cov
*.jl.mem
*.rej
.DS_Store
.benchmarkci
Manifest.toml
benchmark/*.json
coverage
docs/build/
*.rej
env
node_modules
2 changes: 1 addition & 1 deletion RemoteBMI.jl/CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ representative at an online or offline event.
## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported to the community leaders responsible for enforcement at
reported to the community leaders responsible for enforcement:
`[email protected]`.
All complaints will be reviewed and investigated promptly and fairly.

Expand Down
4 changes: 3 additions & 1 deletion RemoteBMI.jl/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@ version = "0.1.0"
BasicModelInterface = "59605e27-edc0-445a-b93d-c09a3a50b330"
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
HTTP = "cd3eb016-35fb-5094-929b-558a96fad6f3"
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
OpenAPI = "d5e62ea6-ddf3-4d43-8e4c-ad5e6c8bfd7d"
TimeZones = "f269a46b-ccf7-5d73-abea-4c690281aa53"
URIs = "5c2747f8-b7ea-4ff2-ba2e-563bfd36b1d4"

[compat]
julia = "1.6"
JSON = "0.21.4"
julia = "1.10"
20 changes: 10 additions & 10 deletions RemoteBMI.jl/README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
# RemoteBMI

[![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://eWaterCycle.github.io/RemoteBMI.jl/stable)
[![In development documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://eWaterCycle.github.io/RemoteBMI.jl/dev)
[![Build Status](https://github.com/eWaterCycle/RemoteBMI.jl/workflows/Test/badge.svg)](https://github.com/eWaterCycle/RemoteBMI.jl/actions)
[![Test workflow status](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Test.yml/badge.svg?branch=main)](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Test.yml?query=branch%3Amain)
[![Lint workflow Status](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Lint.yml/badge.svg?branch=main)](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Lint.yml?query=branch%3Amain)
[![Docs workflow Status](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Docs.yml?query=branch%3Amain)
<!-- [![Stable Documentation](https://img.shields.io/badge/docs-stable-blue.svg)](https://eWaterCycle.github.io/RemoteBMI.jl/stable) -->
<!-- [![In development documentation](https://img.shields.io/badge/docs-dev-blue.svg)](https://eWaterCycle.github.io/RemoteBMI.jl/dev) -->
[![Build Status](https://github.com/eWaterCycle/RemoteBMI.jl/workflows/Julia%20test/badge.svg)](https://github.com/eWaterCycle/RemoteBMI/actions)
[![Test workflow status](https://github.com/eWaterCycle/RemoteBMI/actions/workflows/julia-test.yml/badge.svg?branch=main)](https://github.com/eWaterCycle/RemoteBMI/actions/workflows/julia-test.yml?query=branch%3Amain)
<!-- [![Docs workflow Status](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Docs.yml/badge.svg?branch=main)](https://github.com/eWaterCycle/RemoteBMI.jl/actions/workflows/Docs.yml?query=branch%3Amain) -->

[![Coverage](https://codecov.io/gh/eWaterCycle/RemoteBMI.jl/branch/main/graph/badge.svg)](https://codecov.io/gh/eWaterCycle/RemoteBMI.jl)
[![DOI](https://zenodo.org/badge/DOI/FIXME)](https://doi.org/FIXME)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.1-4baaaa.svg)](CODE_OF_CONDUCT.md)
<!-- TODO filter on Julia component
[![Coverage](https://codecov.io/gh/eWaterCycle/RemoteBMI/branch/main/graph/badge.svg)](https://codecov.io/gh/eWaterCycle/RemoteBMI)
-->

## Usage

Expand All @@ -35,7 +34,8 @@ BestieTemplate.generate("RemoteBMI.jl")
The openapi server stubs where generated using the following command:

```shell
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.8.0/openapi-generator-cli-7.8.0.jar -O openapi-generator-cli.jar
wget https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/7.9.0/openapi-generator-cli-7.9.0.jar -O openapi-generator-cli.jar
java -jar ./openapi-generator-cli.jar generate -i ./openapi.yaml -g julia-server -o julia-server --additional-properties=packageName=BmiServer --additional-properties=exportModels=true
java -jar ./openapi-generator-cli.jar generate -i ./openapi.yaml -g julia-client -o julia-client --additional-properties=packageName=BmiClient --additional-properties=exportModels=true
# Copy the generated files to RemoteBMI.jl/src/
```
32 changes: 8 additions & 24 deletions RemoteBMI.jl/docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,34 +4,18 @@ using Documenter
DocMeta.setdocmeta!(RemoteBMI, :DocTestSetup, :(using RemoteBMI); recursive = true)

const page_rename = Dict("developer.md" => "Developer docs") # Without the numbers

function nice_name(file)
file = replace(file, r"^[0-9]*-" => "")
if haskey(page_rename, file)
return page_rename[file]
end
return splitext(file)[1] |> x -> replace(x, "-" => " ") |> titlecase
end
const numbered_pages = [
file for
file in readdir(joinpath(@__DIR__, "src")) if file != "index.md" && splitext(file)[2] == ".md"
]

makedocs(;
modules = [RemoteBMI],
doctest = true,
linkcheck = false, # Rely on Lint.yml/lychee for the links
authors = "Stefan Verhoeven <[email protected]> and contributors",
authors = "",
repo = "https://github.com/eWaterCycle/RemoteBMI.jl/blob/{commit}{path}#{line}",
sitename = "RemoteBMI.jl",
format = Documenter.HTML(;
prettyurls = true,
canonical = "https://eWaterCycle.github.io/RemoteBMI.jl",
assets = ["assets/style.css"],
),
pages = [
"Home" => "index.md"
[
nice_name(file) => file for
file in readdir(joinpath(@__DIR__, "src")) if file != "index.md" && splitext(file)[2] == ".md"
]
],
format = Documenter.HTML(; canonical = "https://eWaterCycle.github.io/RemoteBMI.jl"),
pages = ["index.md"; numbered_pages],
)

deploydocs(; repo = "github.com/eWaterCycle/RemoteBMI.jl", push_preview = true)
deploydocs(; repo = "github.com/eWaterCycle/RemoteBMI.jl")
5 changes: 4 additions & 1 deletion RemoteBMI.jl/docs/src/91-developer.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ pkg> activate .
pkg> test
```

```shell
julia -e 'using Pkg; Pkg.activate("."); Pkg.test()'
```

## Working on a new issue

We try to keep a linear history in this repo, so it is important to keep your branches up-to-date.
Expand Down Expand Up @@ -86,7 +90,6 @@ We try to keep a linear history in this repo, so it is important to keep your br
Try to create "atomic git commits" (recommended reading: [The Utopic Git History](https://blog.esciencecenter.nl/the-utopic-git-history-d44b81c09593)).

- Make sure the tests pass.

- Fetch any `main` updates from upstream and rebase your branch, if necessary:

```bash
Expand Down
1 change: 0 additions & 1 deletion RemoteBMI.jl/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,3 @@ CurrentModule = RemoteBMI

Documentation for [RemoteBMI](https://github.com/eWaterCycle/RemoteBMI.jl).


24 changes: 22 additions & 2 deletions RemoteBMI.jl/example/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,32 @@ client.get_var_grid('plate_surface__temperature')
0
client.get_grid_type(0)
'uniform_rectilinear'
client.get_grid_shape(0)
dest = reserve_values(client, 'plate_surface__temperature')
r = client.get_value('plate_surface__temperature', dest)
r
client.finalize()
```

Interact using the Julia client.

```julia
# julia --project=$PWD/..
import RemoteBMI.Client: BMIClient
import BasicModelInterface as BMI
model = BMIClient("http://localhost:50555")
m = BMI.initialize(model, joinpath(pwd(), "heat.toml"))
BMI.get_component_name(m)
# "The 2D Heat Equation"
BMI.get_grid_type(m, 0)
# "uniform_rectilinear"
BMI.get_grid_shape(m, 0)
# {}
BMI.get_grid_rank(m, 0)
# 2
BMI.get_grid_x(m, 0, [0.0, 0.0])
```

# Run Wflow.jl

```shell
Expand Down Expand Up @@ -81,9 +101,9 @@ download(toml_url, toml_path)

# Run server
using Wflow
import RemoteBMI
import RemoteBMI.Server: run_bmi_server
port = parse(Int, get(ENV, "BMI_PORT", "50051"))
RemoteBMI.run(Wflow.Model, "0.0.0.0", port)
run_bmi_server(Wflow.Model, "0.0.0.0", port)
```

Interact with it using the Python client.
Expand Down
4 changes: 2 additions & 2 deletions RemoteBMI.jl/example/heat_bmi_server.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# TODO include https://github.com/csdms/bmi-example-julia as test dependency
using Heat

import RemoteBMI
import RemoteBMI.Server: run_bmi_server

port = parse(Int, get(ENV, "BMI_PORT", "50051"))
RemoteBMI.run(Heat.Model, "0.0.0.0", port)
run_bmi_server(Heat.Model, "0.0.0.0", port)
Loading

0 comments on commit a4ad77c

Please sign in to comment.