diff --git a/src/ert/config/ert_config.py b/src/ert/config/ert_config.py index 1ce9b13d0a6..7eb1b0b2f4c 100644 --- a/src/ert/config/ert_config.py +++ b/src/ert/config/ert_config.py @@ -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 @@ -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: @@ -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}" diff --git a/tests/ert/unit_tests/config/test_ert_config.py b/tests/ert/unit_tests/config/test_ert_config.py index 05dac456989..e81f1455fca 100644 --- a/tests/ert/unit_tests/config/test_ert_config.py +++ b/tests/ert/unit_tests/config/test_ert_config.py @@ -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 (