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

Log contents of custom forward model steps #8696

Merged
merged 1 commit into from
Sep 16, 2024
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
9 changes: 9 additions & 0 deletions src/ert/config/ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,14 @@ def _log_config_dict(cls, content_dict: Dict[str, Any]) -> None:

logger.info(f"Content of the config_dict: {tmp_dict}")

@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")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be logged after the ErtConfig is parsed to avoid 1) parsing the config file twice and 2) avoid raising FileNotFoundError instead of ConfigurationValidationError.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed (methinks)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checked and bad permissions for the config file and non-existent config file is handled by __main__.py.

logger.info(
f"Custom forward_model_step {fm_step} installed as: {fm_configuration}"
)

@staticmethod
def apply_config_content_defaults(content_dict: dict, config_dir: str):
if ConfigKeys.ENSPATH not in content_dict:
Expand Down Expand Up @@ -378,6 +386,7 @@ def read_user_config_and_apply_site_config(
) -> ConfigDict:
site_config_dict = cls.read_site_config()
user_config_dict = cls.read_user_config(user_config_file)
cls._log_custom_forward_model_steps(user_config_dict)

for keyword, value in site_config_dict.items():
if keyword == "QUEUE_OPTION":
Expand Down
22 changes: 22 additions & 0 deletions tests/unit_tests/config/test_ert_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,28 @@ def test_logging_config(caplog, config_content, expected):
assert expected in caplog.messages


@pytest.mark.usefixtures("use_tmpdir")
def test_custom_forward_models_are_logged(caplog):
localhack = "localhack.sh"
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("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}"
in caplog.messages
)
assert (
sum("Custom forward_model_step" in logmessage for logmessage in caplog.messages)
== 1
), "check if site-config fm were logged"


@pytest.mark.usefixtures("use_tmpdir")
def test_logging_with_comments(caplog):
"""
Expand Down