petter2025 commited on
Commit
f899610
·
verified ·
1 Parent(s): a094dea

Update config/settings.py

Browse files
Files changed (1) hide show
  1. config/settings.py +53 -20
config/settings.py CHANGED
@@ -1,10 +1,44 @@
1
  """
2
  Configuration management for ARF Demo
 
3
  """
4
- from pydantic import BaseSettings, Field, validator
5
  from typing import Optional, Dict, Any, List
6
  from enum import Enum
7
  import os
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
 
10
  class ARFMode(str, Enum):
@@ -51,37 +85,27 @@ class Settings(BaseSettings):
51
  # ===== Business Configuration =====
52
  engineer_hourly_rate: float = Field(
53
  default=150.0,
54
- ge=50.0,
55
- le=500.0,
56
  description="Engineer hourly rate in USD"
57
  )
58
 
59
  engineer_annual_cost: float = Field(
60
  default=125000.0,
61
- ge=50000.0,
62
- le=250000.0,
63
  description="Engineer annual cost in USD"
64
  )
65
 
66
  default_savings_rate: float = Field(
67
  default=0.82,
68
- ge=0.5,
69
- le=0.95,
70
  description="Default savings rate with ARF"
71
  )
72
 
73
  # ===== UI Configuration =====
74
  auto_refresh_seconds: int = Field(
75
  default=30,
76
- ge=5,
77
- le=300,
78
  description="Auto-refresh interval in seconds"
79
  )
80
 
81
  max_history_items: int = Field(
82
  default=100,
83
- ge=10,
84
- le=1000,
85
  description="Maximum history items to display"
86
  )
87
 
@@ -127,17 +151,26 @@ class Settings(BaseSettings):
127
  use_enum_values = True
128
 
129
 
130
- # Global settings instance
131
- settings = Settings()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
 
134
  def get_settings() -> Settings:
135
  """Get settings instance (singleton pattern)"""
136
- return settings
137
-
138
-
139
- def reload_settings() -> Settings:
140
- """Reload settings from environment"""
141
- global settings
142
- settings = Settings()
143
  return settings
 
1
  """
2
  Configuration management for ARF Demo
3
+ Updated for Pydantic v2 with pydantic-settings
4
  """
 
5
  from typing import Optional, Dict, Any, List
6
  from enum import Enum
7
  import os
8
+ import logging
9
+
10
+ logger = logging.getLogger(__name__)
11
+
12
+ # Try to import from pydantic-settings, fallback to pydantic
13
+ try:
14
+ from pydantic_settings import BaseSettings
15
+ from pydantic import Field, validator
16
+ PYDANTIC_V2 = True
17
+ logger.info("Using pydantic-settings for BaseSettings")
18
+ except ImportError:
19
+ try:
20
+ from pydantic import BaseSettings, Field, validator
21
+ PYDANTIC_V2 = False
22
+ logger.info("Using pydantic.BaseSettings (older version)")
23
+ except ImportError as e:
24
+ logger.error(f"Failed to import pydantic: {e}")
25
+ # Create minimal fallback
26
+ class BaseSettings:
27
+ def __init__(self, **kwargs):
28
+ for k, v in kwargs.items():
29
+ setattr(self, k, v)
30
+
31
+ class Field:
32
+ @staticmethod
33
+ def default(value):
34
+ return value
35
+
36
+ def validator(*args, **kwargs):
37
+ def decorator(func):
38
+ return func
39
+ return decorator
40
+
41
+ PYDANTIC_V2 = False
42
 
43
 
44
  class ARFMode(str, Enum):
 
85
  # ===== Business Configuration =====
86
  engineer_hourly_rate: float = Field(
87
  default=150.0,
 
 
88
  description="Engineer hourly rate in USD"
89
  )
90
 
91
  engineer_annual_cost: float = Field(
92
  default=125000.0,
 
 
93
  description="Engineer annual cost in USD"
94
  )
95
 
96
  default_savings_rate: float = Field(
97
  default=0.82,
 
 
98
  description="Default savings rate with ARF"
99
  )
100
 
101
  # ===== UI Configuration =====
102
  auto_refresh_seconds: int = Field(
103
  default=30,
 
 
104
  description="Auto-refresh interval in seconds"
105
  )
106
 
107
  max_history_items: int = Field(
108
  default=100,
 
 
109
  description="Maximum history items to display"
110
  )
111
 
 
151
  use_enum_values = True
152
 
153
 
154
+ # Global settings instance with fallback
155
+ try:
156
+ settings = Settings()
157
+ except Exception as e:
158
+ logger.warning(f"Failed to load settings from .env: {e}, using defaults")
159
+ settings = Settings(
160
+ arf_mode=ARFMode.DEMO,
161
+ use_mock_arf=True,
162
+ engineer_hourly_rate=150.0,
163
+ engineer_annual_cost=125000.0,
164
+ default_savings_rate=0.82,
165
+ auto_refresh_seconds=30,
166
+ max_history_items=100,
167
+ default_scenario="Cache Miss Storm",
168
+ scenario_config_path="config/scenarios",
169
+ default_safety_mode=SafetyMode.ADVISORY,
170
+ require_approval=True
171
+ )
172
 
173
 
174
  def get_settings() -> Settings:
175
  """Get settings instance (singleton pattern)"""
 
 
 
 
 
 
 
176
  return settings