Skip to content

Commit

Permalink
Add installed jobs in new context system
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindeide committed Jan 15, 2025
1 parent 3f4a2c5 commit 5a05bab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 22 deletions.
31 changes: 17 additions & 14 deletions src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -200,7 +188,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"
Expand Down Expand Up @@ -255,6 +243,18 @@ class EverestConfig(BaseModelWithPropertySupport, BaseModelWithContextSupport):
config_path: Path = Field()
model_config = ConfigDict(extra="forbid")

@field_validator("install_jobs")
@classmethod
def inject_system_installed_jobs(
cls, v: list[InstallJobConfig], info: ValidationInfo
) -> str:
v = [] if v is None else v
if info.context:
installed_jobs = info.context.get(info.field_name)
if installed_jobs:
v.extend(installed_jobs.keys())
return v

@model_validator(mode="after")
def validate_queue_system(self) -> Self: # pylint: disable=E0213
if self.server is None:
Expand Down Expand Up @@ -284,7 +284,6 @@ 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

errors = []
for fm_job in forward_model_jobs:
Expand Down Expand Up @@ -818,10 +817,14 @@ def load_file(config_file: str) -> "EverestConfig":
@classmethod
def with_plugins(cls, config_dict):
site_config = ErtConfig.read_site_config()
ert_config: ErtConfig = ErtConfig.with_plugins().from_dict(
config_dict=site_config
)
queue_config = QueueConfig.from_dict(site_config)
context = {
"activate_script": ErtPluginManager().activate_script(),
"queue_system": queue_config.queue_options,
"install_jobs": ert_config.installed_forward_model_steps,
}
with init_context(context):
return EverestConfig(**config_dict)
Expand Down
8 changes: 0 additions & 8 deletions tests/everest/test_util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.config_keys import ConfigKeys
from everest.detached import ServerStatus
from everest.strings import SERVER_STATUS
Expand Down Expand Up @@ -134,13 +133,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"},
Expand Down

0 comments on commit 5a05bab

Please sign in to comment.