Skip to content

Commit

Permalink
⚡ perf: Optimize config wrapper
Browse files Browse the repository at this point in the history
  • Loading branch information
raxhvl committed Oct 16, 2024
1 parent f9b82fd commit 0cc2e9d
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/config/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,11 @@ class Config(BaseModel):
remote_nodes: List[RemoteNode]


class EnvConfig:
"""
Loads and validates environment configuration from `env.yaml`.
Attributes:
- config (Config): An instance of the Config class containing validated settings.
class EnvConfig(Config):
"""Loads and validates environment configuration from `env.yaml`.
Raises:
- ValueError: If the configuration is invalid.
This is a wrapper class for the Config model. It reads a config file
from disk into a Config model and then exposes it.
"""

def __init__(self):
Expand All @@ -75,15 +71,11 @@ def __init__(self):
with ENV_PATH.open("r") as file:
config_data = yaml.safe_load(file)
try:
self.config = Config(**config_data) # Validate and parse with Pydantic
# Validate and parse with Pydantic
super().__init__(**config_data)
except ValidationError as e:
raise ValueError(f"Invalid configuration: {e}")

@property
def remote_nodes(self):
"""Returns the list of remote nodes from the configuration."""
return self.config.remote_nodes


# The default configuration represented as a Config model.
DEFAULT_CONFIG = Config(
Expand Down

0 comments on commit 0cc2e9d

Please sign in to comment.