Update config/settings.py
Browse files- config/settings.py +60 -30
config/settings.py
CHANGED
|
@@ -1,6 +1,6 @@
|
|
| 1 |
"""
|
| 2 |
Configuration management for ARF Demo
|
| 3 |
-
Updated with REAL ARF installation detection
|
| 4 |
"""
|
| 5 |
from typing import Optional, Dict, Any, List
|
| 6 |
from enum import Enum
|
|
@@ -162,6 +162,26 @@ class Settings(BaseSettings):
|
|
| 162 |
)
|
| 163 |
|
| 164 |
# ===== Validation =====
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 165 |
@validator("arf_api_key")
|
| 166 |
def validate_api_key(cls, v: Optional[str], values: Dict[str, Any]) -> Optional[str]:
|
| 167 |
if values.get("arf_mode") == ARFMode.ENTERPRISE and not v:
|
|
@@ -273,6 +293,44 @@ class Settings(BaseSettings):
|
|
| 273 |
use_enum_values = True
|
| 274 |
|
| 275 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 276 |
# Global settings instance with installation detection
|
| 277 |
try:
|
| 278 |
# First detect installation
|
|
@@ -315,32 +373,4 @@ except Exception as e:
|
|
| 315 |
|
| 316 |
def get_settings() -> Settings:
|
| 317 |
"""Get settings instance (singleton pattern)"""
|
| 318 |
-
return settings
|
| 319 |
-
|
| 320 |
-
|
| 321 |
-
def print_installation_status():
|
| 322 |
-
"""Print installation status to console"""
|
| 323 |
-
s = get_settings()
|
| 324 |
-
status = s.get_installation_status()
|
| 325 |
-
|
| 326 |
-
print("=" * 70)
|
| 327 |
-
print("π ARF Ultimate Investor Demo - Installation Status")
|
| 328 |
-
print("=" * 70)
|
| 329 |
-
|
| 330 |
-
print(f"π¦ ARF OSS: {'β
v' + s.arf_oss_version if s.arf_oss_installed else 'β οΈ Not installed'}")
|
| 331 |
-
print(f"π’ Enterprise: {'β
v' + s.arf_enterprise_version if s.arf_enterprise_installed else 'β οΈ Not installed'}")
|
| 332 |
-
print(f"π― Mode: {s.arf_mode.value}")
|
| 333 |
-
print(f"π€ Using True ARF: {'β
Yes' if s.use_true_arf else 'β οΈ Mock mode'}")
|
| 334 |
-
|
| 335 |
-
recommendations = s.get_installation_recommendations()
|
| 336 |
-
if recommendations:
|
| 337 |
-
print("\nπ‘ Recommendations:")
|
| 338 |
-
for rec in recommendations:
|
| 339 |
-
print(f" β’ {rec}")
|
| 340 |
-
|
| 341 |
-
print("=" * 70)
|
| 342 |
-
|
| 343 |
-
|
| 344 |
-
# Print status on import (but only if not in test mode)
|
| 345 |
-
if __name__ != "__main__" and "pytest" not in sys.modules:
|
| 346 |
-
print_installation_status()
|
|
|
|
| 1 |
"""
|
| 2 |
Configuration management for ARF Demo
|
| 3 |
+
Updated with REAL ARF installation detection - FIXED VERSION
|
| 4 |
"""
|
| 5 |
from typing import Optional, Dict, Any, List
|
| 6 |
from enum import Enum
|
|
|
|
| 162 |
)
|
| 163 |
|
| 164 |
# ===== Validation =====
|
| 165 |
+
@validator("arf_mode", "default_safety_mode", pre=True)
|
| 166 |
+
def validate_enums(cls, v):
|
| 167 |
+
"""Convert strings to enum values if needed"""
|
| 168 |
+
if isinstance(v, str):
|
| 169 |
+
# Try to match enum values
|
| 170 |
+
if hasattr(cls, '__fields__'):
|
| 171 |
+
field_name = None
|
| 172 |
+
for field in cls.__fields__.values():
|
| 173 |
+
if field.name == 'arf_mode' and isinstance(v, str):
|
| 174 |
+
try:
|
| 175 |
+
return ARFMode(v.lower())
|
| 176 |
+
except ValueError:
|
| 177 |
+
return ARFMode.DEMO
|
| 178 |
+
elif field.name == 'default_safety_mode' and isinstance(v, str):
|
| 179 |
+
try:
|
| 180 |
+
return SafetyMode(v.lower())
|
| 181 |
+
except ValueError:
|
| 182 |
+
return SafetyMode.ADVISORY
|
| 183 |
+
return v
|
| 184 |
+
|
| 185 |
@validator("arf_api_key")
|
| 186 |
def validate_api_key(cls, v: Optional[str], values: Dict[str, Any]) -> Optional[str]:
|
| 187 |
if values.get("arf_mode") == ARFMode.ENTERPRISE and not v:
|
|
|
|
| 293 |
use_enum_values = True
|
| 294 |
|
| 295 |
|
| 296 |
+
def print_installation_status():
|
| 297 |
+
"""Print installation status to console - SAFE VERSION"""
|
| 298 |
+
try:
|
| 299 |
+
# Create settings instance first to avoid circular imports
|
| 300 |
+
installation_info = Settings.detect_installation()
|
| 301 |
+
|
| 302 |
+
# Create settings with installation info
|
| 303 |
+
s = Settings(
|
| 304 |
+
arf_oss_installed=installation_info["oss_installed"],
|
| 305 |
+
arf_enterprise_installed=installation_info["enterprise_installed"],
|
| 306 |
+
arf_oss_version=installation_info["oss_version"],
|
| 307 |
+
arf_enterprise_version=installation_info["enterprise_version"],
|
| 308 |
+
)
|
| 309 |
+
|
| 310 |
+
print("=" * 70)
|
| 311 |
+
print("π ARF Ultimate Investor Demo - Installation Status")
|
| 312 |
+
print("=" * 70)
|
| 313 |
+
|
| 314 |
+
print(f"π¦ ARF OSS: {'β
v' + s.arf_oss_version if s.arf_oss_installed else 'β οΈ Not installed'}")
|
| 315 |
+
print(f"π’ Enterprise: {'β
v' + s.arf_enterprise_version if s.arf_enterprise_installed else 'β οΈ Not installed'}")
|
| 316 |
+
|
| 317 |
+
# Safe enum access - convert to string first
|
| 318 |
+
mode_str = str(s.arf_mode) if hasattr(s.arf_mode, 'value') else str(s.arf_mode)
|
| 319 |
+
print(f"π― Mode: {mode_str.upper()}")
|
| 320 |
+
print(f"π€ Using True ARF: {'β
Yes' if s.use_true_arf else 'β οΈ Mock mode'}")
|
| 321 |
+
|
| 322 |
+
recommendations = s.get_installation_recommendations()
|
| 323 |
+
if recommendations:
|
| 324 |
+
print("\nπ‘ Recommendations:")
|
| 325 |
+
for rec in recommendations:
|
| 326 |
+
print(f" β’ {rec}")
|
| 327 |
+
|
| 328 |
+
print("=" * 70)
|
| 329 |
+
|
| 330 |
+
except Exception as e:
|
| 331 |
+
print(f"β οΈ Could not print installation status: {e}")
|
| 332 |
+
|
| 333 |
+
|
| 334 |
# Global settings instance with installation detection
|
| 335 |
try:
|
| 336 |
# First detect installation
|
|
|
|
| 373 |
|
| 374 |
def get_settings() -> Settings:
|
| 375 |
"""Get settings instance (singleton pattern)"""
|
| 376 |
+
return settings
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|