Skip to content

Commit

Permalink
Remove logging_level setter from everest config
Browse files Browse the repository at this point in the history
Remove workaround to allow property setters for EverestConfig
  • Loading branch information
DanSava committed Jan 21, 2025
1 parent 6a978df commit 0b80ac1
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 33 deletions.
26 changes: 1 addition & 25 deletions src/everest/config/everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
from typing import (
TYPE_CHECKING,
Annotated,
Literal,
Optional,
Protocol,
Self,
Expand Down Expand Up @@ -81,21 +80,6 @@ def get_system_installed_jobs():
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.
class BaseModelWithPropertySupport(BaseModel):
@no_type_check
def __setattr__(self, name, value):
"""
To be able to use properties with setters
"""
try:
getattr(self.__class__, name).fset(self, value)
except AttributeError:
super().__setattr__(name, value)


class EverestValidationError(ValueError):
def __init__(self):
super().__init__()
Expand Down Expand Up @@ -134,7 +118,7 @@ class HasName(Protocol):
name: str


class EverestConfig(BaseModelWithPropertySupport): # type: ignore
class EverestConfig(BaseModel): # type: ignore
controls: Annotated[list[ControlConfig], AfterValidator(unique_items)] = Field(
description="""Defines a list of controls.
Controls should have unique names each control defines
Expand Down Expand Up @@ -570,14 +554,6 @@ def logging_level(self) -> int:
}
return levels.get(level.lower(), logging.INFO)

@logging_level.setter
def logging_level(
self, level: Literal["debug", "info", "warning", "error", "critical"]
):
env = self.environment
assert env is not None
env.log_level = level # pylint:disable = E0237

@property
def config_directory(self) -> str | None:
if self.config_path is not None:
Expand Down
4 changes: 1 addition & 3 deletions src/everest/detached/jobs/everserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,6 @@ def main():
arg_parser.add_argument("--debug", action="store_true")
options = arg_parser.parse_args()
config = EverestConfig.load_file(options.config_file)
if options.debug:
config.logging_level = "debug"
status_path = ServerConfig.get_everserver_status_path(config.output_dir)
host_file = ServerConfig.get_hostfile_path(config.output_dir)

Expand All @@ -253,7 +251,7 @@ def main():
if config.log_dir is None
else Path(config.log_dir)
),
logging_level=config.logging_level,
logging_level=config.logging_level if not options.debug else logging.DEBUG,
)

update_everserver_status(status_path, ServerStatus.starting)
Expand Down
5 changes: 0 additions & 5 deletions tests/everest/test_everest_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -281,11 +281,6 @@ def test_that_log_level_property_is_consistent_with_environment_log_level():
config.environment.log_level = lvl_str
assert config.logging_level == lvl_int

for lvl_str, lvl_int in levels.items():
config.logging_level = lvl_str
assert config.environment.log_level == lvl_str
assert config.logging_level == lvl_int


@pytest.mark.parametrize("config_class", [SimulatorConfig, ServerConfig])
@pytest.mark.parametrize("queue_system", ["lsf", "torque", "slurm", "local"])
Expand Down

0 comments on commit 0b80ac1

Please sign in to comment.