-
Notifications
You must be signed in to change notification settings - Fork 110
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
Fix bug where site config was not propagated to Everest config #9719
base: main
Are you sure you want to change the base?
Changes from 1 commit
f5b6de1
6337e95
584a340
7bd65e4
1017e5d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from collections.abc import Iterator | ||
from contextlib import contextmanager | ||
from contextvars import ContextVar | ||
from typing import Any | ||
|
||
from pydantic import BaseModel | ||
|
||
init_context_var = ContextVar("_init_context_var", default=None) | ||
|
||
|
||
@contextmanager | ||
def init_context(value: dict[str, Any]) -> Iterator[None]: | ||
token = init_context_var.set(value) # type: ignore | ||
try: | ||
yield | ||
finally: | ||
init_context_var.reset(token) | ||
|
||
|
||
class BaseModelWithContextSupport(BaseModel): | ||
def __init__(__pydantic_self__, **data: Any) -> None: | ||
__pydantic_self__.__pydantic_validator__.validate_python( | ||
data, | ||
self_instance=__pydantic_self__, | ||
context=init_context_var.get(), | ||
) |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,6 +28,9 @@ | |
from ruamel.yaml import YAML, YAMLError | ||
|
||
from ert.config import ErtConfig | ||
from ert.config.parsing import BaseModelWithContextSupport | ||
from ert.config.parsing.base_model_context import init_context | ||
from ert.plugins import ErtPluginManager | ||
from everest.config.control_variable_config import ControlVariableGuessListConfig | ||
from everest.config.install_template_config import InstallTemplateConfig | ||
from everest.config.server_config import ServerConfig | ||
|
@@ -134,7 +137,7 @@ class HasName(Protocol): | |
name: str | ||
|
||
|
||
class EverestConfig(BaseModelWithPropertySupport): # type: ignore | ||
class EverestConfig(BaseModelWithPropertySupport, BaseModelWithContextSupport): # type: ignore | ||
controls: Annotated[list[ControlConfig], AfterValidator(unique_items)] = Field( | ||
description="""Defines a list of controls. | ||
Controls should have unique names each control defines | ||
|
@@ -807,6 +810,15 @@ def load_file(config_file: str) -> "EverestConfig": | |
|
||
raise exp from error | ||
|
||
@classmethod | ||
def with_plugins(cls, config_dict): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am a bit confused as to why mypy is not complaining about the missing type for the argument |
||
context = {} | ||
activate_script = ErtPluginManager().activate_script() | ||
if activate_script: | ||
context["activate_script"] = ErtPluginManager().activate_script() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think you can just have context["activate_script"] = activate_script in place of context["activate_script"] = ErtPluginManager().activate_script() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a need to re-invoke |
||
with init_context(context): | ||
return cls(**config_dict) | ||
|
||
@staticmethod | ||
def load_file_with_argparser( | ||
config_path, parser: ArgumentParser | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a test that runs this line? EDIT: I see running
test_detached
triggers it, but do any of the ERT tests run it? Is this mainly meant for things we run via Everest?