Skip to content

Commit

Permalink
Ensure SETENV is also substituted when writing json
Browse files Browse the repository at this point in the history
This is a regression from 1ae12f6
  • Loading branch information
berland committed Jan 24, 2025
1 parent 1f604fe commit cfbce48
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -528,7 +528,7 @@ def from_dict(cls, config_dict) -> Self:

env_vars = {}
for key, val in config_dict.get("SETENV", []):
env_vars[key] = val
env_vars[key] = substitutions.substitute(val)

return cls(
substitutions=substitutions,
Expand Down Expand Up @@ -753,7 +753,7 @@ def _create_list_of_forward_model_steps_to_run(

env_vars = {}
for key, val in config_dict.get("SETENV", []):
env_vars[key] = val
env_vars[key] = substitutions.substitute(val)

for fm_step_description in config_dict.get(ConfigKeys.FORWARD_MODEL, []):
if len(fm_step_description) > 1:
Expand Down
23 changes: 23 additions & 0 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -939,6 +939,29 @@ def test_fm_step_config_via_plugin_is_overridden_by_setenv(monkeypatch):
assert step_json["jobList"][0]["environment"]["STEP_LOCAL_VAR"] == "com_from_plugin"


@pytest.mark.usefixtures("use_tmpdir")
def test_setenv_will_be_substituted_in_jobs_json(monkeypatch):
Path("config.ert").write_text(
dedent(
"""
NUM_REALIZATIONS 1
SETENV FOO <NUM_CPU>
NUM_CPU 2
"""
),
encoding="utf-8",
)
ert_config = ErtConfig.with_plugins().from_file("config.ert")
step_json = create_forward_model_json(
context=ert_config.substitutions,
forward_model_steps=ert_config.forward_model_steps,
env_vars=ert_config.env_vars,
env_pr_fm_step=ert_config.env_pr_fm_step,
run_id=None,
)
assert step_json["global_environment"]["FOO"] == "2"


@pytest.mark.usefixtures("use_tmpdir")
def test_fm_step_config_via_plugin_does_not_override_default_env(monkeypatch):
monkeypatch.setattr(
Expand Down

0 comments on commit cfbce48

Please sign in to comment.