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 16, 2025
1 parent 3635c08 commit 1d74782
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 27 deletions.
31 changes: 12 additions & 19 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 @@ -284,7 +272,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:
Expand Down Expand Up @@ -769,7 +758,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"]:
Expand All @@ -786,16 +775,16 @@ 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):
raise FileNotFoundError(f"File not found: {config_path}")

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 = []
Expand All @@ -818,13 +807,17 @@ 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)
return cls(**config_dict)

@staticmethod
def load_file_with_argparser(
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 1d74782

Please sign in to comment.