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

Configure max number of model instances #61

Open
wants to merge 12 commits into
base: develop
Choose a base branch
from
3 changes: 2 additions & 1 deletion babelizer/data/cookiecutter.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
"libraries": [],
"library_dirs": [],
"include_dirs": [],
"extra_compile_args": []
"extra_compile_args": [],
"max_instances": 3
},
"info": {
"full_name": "CSDMS",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module bmi_interoperability

implicit none

integer, parameter :: N_MODELS = 2048
integer, parameter :: N_MODELS = {{ cookiecutter.build.max_instances }}
type ({{ component.entry_point }}) :: model_array(N_MODELS)
logical :: model_avail(N_MODELS) = .true.

Expand Down
6 changes: 6 additions & 0 deletions babelizer/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ def validate(config):
"library_dirs",
"include_dirs",
"extra_compile_args",
"max_instances",
),
)
validate_dict(config["package"], required=("name", "requirements"), optional={})
Expand Down Expand Up @@ -313,6 +314,9 @@ def norm(config):
except KeyError:
pass

if "max_instances" not in build:
build["max_instances"] = 8

if "entry_point" in config["library"]:
libraries = BabelMetadata._handle_old_style_entry_points(config["library"])
else:
Expand All @@ -335,6 +339,7 @@ def norm(config):
"library_dirs": build["library_dirs"],
"include_dirs": build["include_dirs"],
"extra_compile_args": build["extra_compile_args"],
"max_instances": build["max_instances"],
},
"package": {
"name": config["package"]["name"],
Expand Down Expand Up @@ -446,6 +451,7 @@ def as_cookiecutter_context(self):
"library_dirs": self._meta["build"]["library_dirs"],
"include_dirs": self._meta["build"]["include_dirs"],
"extra_compile_args": self._meta["build"]["extra_compile_args"],
"max_instances": self._meta["build"]["max_instances"],
},
"info": {
"full_name": self._meta["info"]["package_author"],
Expand Down
66 changes: 63 additions & 3 deletions external/tests/test_fortran.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
import subprocess
import sys

import git
import pytest
import toml
from click.testing import CliRunner

from babelizer.cli import babelize
Expand All @@ -16,17 +19,59 @@
extra_opts += ["--no-build-isolation"]


def test_babelize_init_fortran(tmpdir, datadir):
runner = CliRunner()
@pytest.mark.dependency()
def test_babelize_init_works(tmpdir, datadir):
runner = CliRunner(mix_stderr=False)
with tmpdir.as_cwd():
result = runner.invoke(babelize, ["init", str(datadir / "babel.toml")])

assert result.stdout.strip() == str(tmpdir / "pymt_heatf")
assert result.exit_code == 0
assert pathlib.Path("pymt_heatf").exists()
assert (pathlib.Path("pymt_heatf") / "babel.toml").is_file()

repo = git.Repo("pymt_heatf")

assert not repo.bare


@pytest.mark.dependency(depends=["test_babelize_init_works"])
@pytest.mark.parametrize("max_instances", [8, 32, None])
def test_babelize_init_fortran_with_user_instances(tmpdir, datadir, max_instances):
runner = CliRunner(mix_stderr=False)

babel_toml = toml.load(datadir / "babel.toml")
babel_toml["build"]["max_instances"] = max_instances

if max_instances is None:
babel_toml["build"].pop("max_instances", None)
max_instances = 8

with tmpdir.as_cwd():
shutil.copy(datadir / "babel.toml", ".")
with open("babel.toml", "w") as fp:
toml.dump(babel_toml, fp)

result = runner.invoke(babelize, ["init", "babel.toml"])

assert result.stdout.strip() == str(tmpdir / "pymt_heatf")
assert result.exit_code == 0
assert pathlib.Path("pymt_heatf").exists()
assert (pathlib.Path("pymt_heatf") / "babel.toml").is_file()

meta = toml.load("pymt_heatf/babel.toml")

assert "max_instances" in meta["build"]
assert meta["build"]["max_instances"] == max_instances


@pytest.mark.dependency(depends=["test_babelize_init_works"])
def test_babelize_build_fortran_example(tmpdir, datadir):
runner = CliRunner(mix_stderr=False)

with tmpdir.as_cwd():
runner.invoke(babelize, ["init", str(datadir / "babel.toml")])

with tmpdir.as_cwd():
try:
result = subprocess.run(
["pip", "install", "-e", "."] + extra_opts,
Expand Down Expand Up @@ -63,3 +108,18 @@ def test_babelize_init_fortran(tmpdir, datadir):
assert err.output is None, err.output

assert result.returncode == 0


@pytest.mark.dependency(depends=["test_babelize_init_works"])
def test_babelize_update_fortran(tmpdir, datadir):
runner = CliRunner(mix_stderr=False)

with tmpdir.as_cwd():
runner.invoke(babelize, ["init", str(datadir / "babel.toml")])

with tmpdir.as_cwd():
result = runner.invoke(babelize, ["--cd", "pymt_heatf", "update"])

assert result.exit_code == 0
assert pathlib.Path("pymt_heatf").exists()
assert "re-rendering" in result.stderr