Skip to content

Commit

Permalink
Fix logging of custom forward model steps
Browse files Browse the repository at this point in the history
  • Loading branch information
eivindjahren committed Jan 28, 2025
1 parent 2154d52 commit 6176e92
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
7 changes: 5 additions & 2 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import copy
import logging
import os
import re
from collections import defaultdict
from collections.abc import Sequence
from dataclasses import field
Expand Down Expand Up @@ -70,6 +71,8 @@

logger = logging.getLogger(__name__)

EMPTY_LINES = re.compile(r"\n[\s\n]*\n")


def site_config_location() -> str | None:
if "ERT_SITE_CONFIG" in os.environ:
Expand Down Expand Up @@ -609,8 +612,8 @@ def _log_config_dict(cls, content_dict: dict[str, Any]) -> None:
@classmethod
def _log_custom_forward_model_steps(cls, user_config: ConfigDict) -> None:
for fm_step, fm_step_filename in user_config.get(ConfigKeys.INSTALL_JOB, []):
fm_configuration = (
Path(fm_step_filename).read_text(encoding="utf-8").strip()
fm_configuration = EMPTY_LINES.sub(
"\n", (Path(fm_step_filename).read_text(encoding="utf-8").strip())
)
logger.info(
f"Custom forward_model_step {fm_step} installed as: {fm_configuration}"
Expand Down
6 changes: 4 additions & 2 deletions tests/ert/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,14 +182,16 @@ def test_custom_forward_models_are_logged(caplog):
Path(localhack).write_text("", encoding="utf-8")
st = os.stat(localhack)
os.chmod(localhack, st.st_mode | stat.S_IEXEC)
Path("foo_fm").write_text(f"EXECUTABLE {localhack}", encoding="utf-8")
Path("foo_fm").write_text(
f"-- A comment\n \nEXECUTABLE {localhack}\n\n\n", encoding="utf-8"
)
Path("config.ert").write_text(
"NUM_REALIZATIONS 1\nINSTALL_JOB foo_fm foo_fm", encoding="utf-8"
)
with caplog.at_level(logging.INFO):
ErtConfig.from_file("config.ert")
assert (
f"Custom forward_model_step foo_fm installed as: EXECUTABLE {localhack}"
f"Custom forward_model_step foo_fm installed as: -- A comment\nEXECUTABLE {localhack}"
in caplog.messages
)
assert (
Expand Down

0 comments on commit 6176e92

Please sign in to comment.