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

Fix logging of custom forward model steps #9893

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading