From 749a7b838a1c443cfc3bba97f7032499096b8286 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=98yvind=20Eide?= Date: Wed, 15 Jan 2025 08:48:34 +0100 Subject: [PATCH] Add installed jobs in new context system --- src/everest/config/everest_config.py | 34 ++++++++++++---------------- tests/everest/test_egg_simulation.py | 1 - tests/everest/test_util.py | 8 ------- 3 files changed, 14 insertions(+), 29 deletions(-) diff --git a/src/everest/config/everest_config.py b/src/everest/config/everest_config.py index 34c7669f907..00b657f1aa5 100644 --- a/src/everest/config/everest_config.py +++ b/src/everest/config/everest_config.py @@ -73,18 +73,6 @@ from pydantic_core import ErrorDetails -def _dummy_ert_config(): - site_config = ErtConfig.read_site_config() - dummy_config = {"NUM_REALIZATIONS": 1, "ENSPATH": "."} - dummy_config.update(site_config) - return ErtConfig.with_plugins().from_dict(config_dict=dummy_config) - - -def get_system_installed_jobs(): - """Returns list of all system installed job names""" - return list(_dummy_ert_config().installed_forward_model_steps.keys()) - - # Makes property.setter work # Based on https://github.com/pydantic/pydantic/issues/1577#issuecomment-790506164 # We should use computed_property instead of this, when upgrading to pydantic 2. @@ -196,7 +184,7 @@ class EverestConfig(BaseModelWithPropertySupport, BaseModelWithContextSupport): default=None, description="A list of output constraints with unique names." ) install_jobs: list[InstallJobConfig] | None = Field( - default=None, description="A list of jobs to install" + default=None, description="A list of jobs to install", validate_default=True ) install_workflow_jobs: list[InstallJobConfig] | None = Field( default=None, description="A list of workflow jobs to install" @@ -280,7 +268,8 @@ def validate_forward_model_job_name_installed(self, info: ValidationInfo) -> Sel return self installed_jobs_name = [job.name for job in install_jobs] installed_jobs_name += list(script_names) # default jobs - installed_jobs_name += get_system_installed_jobs() # system jobs + if info.context: # Add plugin jobs + installed_jobs_name += info.context.get("install_jobs", {}).keys() errors = [] for fm_job in forward_model_jobs: @@ -765,7 +754,7 @@ def with_defaults(cls, **kwargs): "model": {"realizations": [0]}, } - return cls.model_validate({**defaults, **kwargs}) + return cls.with_plugins({**defaults, **kwargs}) @staticmethod def lint_config_dict(config: dict) -> list["ErrorDetails"]: @@ -782,8 +771,8 @@ def lint_config_dict_with_raise(config: dict): # more understandable EverestConfig.model_validate(config) - @staticmethod - def load_file(config_file: str) -> "EverestConfig": + @classmethod + def load_file(cls, config_file: str): config_path = os.path.realpath(config_file) if not os.path.isfile(config_path): @@ -791,7 +780,7 @@ def load_file(config_file: str) -> "EverestConfig": config_dict = yaml_file_to_substituted_config_dict(config_path) try: - return EverestConfig.model_validate(config_dict) + return cls.with_plugins(config_dict) except ValidationError as error: exp = EverestValidationError() file_content = [] @@ -813,9 +802,14 @@ def load_file(config_file: str) -> "EverestConfig": @classmethod def with_plugins(cls, config_dict): - context = {} - activate_script = ErtPluginManager().activate_script() site_config = ErtConfig.read_site_config() + ert_config: ErtConfig = ErtConfig.with_plugins().from_dict( + config_dict=site_config + ) + context = { + "install_jobs": ert_config.installed_forward_model_steps, + } + activate_script = ErtPluginManager().activate_script() if site_config: context["queue_system"] = QueueConfig.from_dict(site_config).queue_options if activate_script: diff --git a/tests/everest/test_egg_simulation.py b/tests/everest/test_egg_simulation.py index d20de3a3f9d..64c007dd233 100644 --- a/tests/everest/test_egg_simulation.py +++ b/tests/everest/test_egg_simulation.py @@ -594,7 +594,6 @@ def test_opm_fail_default_summary_keys(copy_egg_test_data_to_tmp): config = EverestConfig.load_file(CONFIG_FILE) # The Everest config file will fail to load as an Eclipse data file config.model.data_file = os.path.realpath(CONFIG_FILE) - assert len(EverestConfig.lint_config_dict(config.to_dict())) == 0 ert_config = _everest_to_ert_config_dict(config) diff --git a/tests/everest/test_util.py b/tests/everest/test_util.py index 60e3275811b..a97b0e5670f 100644 --- a/tests/everest/test_util.py +++ b/tests/everest/test_util.py @@ -7,7 +7,6 @@ from everest import util from everest.bin.utils import report_on_previous_run from everest.config import EverestConfig, ServerConfig -from everest.config.everest_config import get_system_installed_jobs from everest.detached import ServerStatus from everest.strings import SERVER_STATUS from tests.everest.utils import ( @@ -133,13 +132,6 @@ def test_get_everserver_status_path(copy_math_func_test_data_to_tmp): assert path == expected_path -def test_get_system_installed_job_names(): - job_names = get_system_installed_jobs() - assert job_names is not None - assert isinstance(job_names, list) - assert len(job_names) > 0 - - @patch( "everest.bin.utils.everserver_status", return_value={"status": ServerStatus.failed, "message": "mock error"},