Skip to content

Commit

Permalink
Bool variants always override the model
Browse files Browse the repository at this point in the history
  • Loading branch information
penguian committed Aug 13, 2024
1 parent 730ab8a commit 652c633
Showing 1 changed file with 16 additions and 24 deletions.
40 changes: 16 additions & 24 deletions packages/um/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,21 +37,22 @@ class Um(Package):
variant("site_platform", default="none", description="Site platform",
values="*", multi=False)

_bool_variants = (
"COUPLER",
_bool_off_variants = (
"DR_HOOK",
"eccodes",
"netcdf",
"openmp",
"platagnostic",
"thread_utils")
for b in _bool_variants:
variant(b, default=False, description=b, multi=False)

_bool_off_variants = (f"{v}_off" for v in _bool_variants)
for b in _bool_off_variants:
variant(b, default=False, description=b, multi=False)

_bool_on_variants = (
"eccodes",
"netcdf",
"openmp")
for b in _bool_on_variants:
variant(b, default=True, description=b, multi=False)

_bool_variants = _bool_off_variants + _bool_on_variants

_str_variants = (
"casim_rev",
"casim_sources",
Expand All @@ -66,6 +67,7 @@ class Um(Package):
"config_revision",
"config_root_path",
"config_type",
"COUPLER",
"extract",
"fcflags_overrides",
"gwd_ussp_precision",
Expand Down Expand Up @@ -203,22 +205,12 @@ def setup_build_environment(self, env):
f"The {model} model uses {comp}_rev={comp_rev} but"
f"the spec implies {comp}_rev={spec_um_rev}.")

# Override those environment variables where a boolean variant is True.
# Override those environment variables corresponding to a bool variant.
_bool_to_str = lambda b: "true" if b else "false"
for b in self._bool_variants:
b_value = spec.variants[b].value
if b_value:
b_off = f"{b}_off"
b_off_value = spec.variants[b_off].value
if b_off_value:
raise SpecError(
f"Variants +{b} and +{b_off} contradict each other.")
config_env[b] = "true"
for b in self._bool_off_variants:
b_value = spec.variants[b].value
if b_value:
config_env[b] = "false"

# Override those environment variables where a variant is specified.
config_env[b] = _bool_to_str(spec.variants[b].value)

# Override those environment variables where a string variant is specified.
for v in self._str_variants:
v_value = spec.variants[v].value
if v_value != "none":
Expand Down

0 comments on commit 652c633

Please sign in to comment.