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 17, 2025
1 parent 33e56c3 commit f9b110d
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 28 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 @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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"]:
Expand All @@ -782,16 +771,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 @@ -814,13 +803,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
1 change: 0 additions & 1 deletion tests/everest/test_egg_simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,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)

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 f9b110d

Please sign in to comment.