more decoupling
This commit is contained in:
@@ -5,14 +5,15 @@ Loads and validates framework configuration files.
|
||||
"""
|
||||
|
||||
import json
|
||||
from pathlib import Path
|
||||
from typing import Dict, Any, List, Optional
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
|
||||
@dataclass
|
||||
class FrameworkConfig:
|
||||
"""Framework metadata"""
|
||||
|
||||
name: str
|
||||
slug: str
|
||||
version: str
|
||||
@@ -25,18 +26,19 @@ class FrameworkConfig:
|
||||
@dataclass
|
||||
class SystemConfig:
|
||||
"""System configuration"""
|
||||
|
||||
key: str
|
||||
name: str
|
||||
slug: str
|
||||
title: str
|
||||
tagline: str
|
||||
port: int
|
||||
icon: str
|
||||
slug: str = ""
|
||||
title: str = ""
|
||||
tagline: str = ""
|
||||
icon: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class ComponentConfig:
|
||||
"""Component configuration"""
|
||||
|
||||
name: str
|
||||
title: str
|
||||
description: str
|
||||
@@ -54,7 +56,7 @@ class ConfigLoader:
|
||||
self.systems: List[SystemConfig] = []
|
||||
self.components: Dict[str, Dict[str, ComponentConfig]] = {}
|
||||
|
||||
def load(self) -> 'ConfigLoader':
|
||||
def load(self) -> "ConfigLoader":
|
||||
"""Load configuration from file"""
|
||||
with open(self.config_path) as f:
|
||||
self.raw_config = json.load(f)
|
||||
@@ -67,25 +69,25 @@ class ConfigLoader:
|
||||
|
||||
def _parse_framework(self):
|
||||
"""Parse framework metadata"""
|
||||
fw = self.raw_config['framework']
|
||||
fw = self.raw_config["framework"]
|
||||
self.framework = FrameworkConfig(**fw)
|
||||
|
||||
def _parse_systems(self):
|
||||
"""Parse system configurations"""
|
||||
for sys in self.raw_config['systems']:
|
||||
for sys in self.raw_config["systems"]:
|
||||
self.systems.append(SystemConfig(**sys))
|
||||
|
||||
def _parse_components(self):
|
||||
"""Parse component configurations"""
|
||||
comps = self.raw_config['components']
|
||||
comps = self.raw_config["components"]
|
||||
|
||||
# Shared components
|
||||
self.components['shared'] = {}
|
||||
for key, value in comps.get('shared', {}).items():
|
||||
self.components['shared'][key] = ComponentConfig(**value)
|
||||
self.components["shared"] = {}
|
||||
for key, value in comps.get("shared", {}).items():
|
||||
self.components["shared"][key] = ComponentConfig(**value)
|
||||
|
||||
# System-specific components
|
||||
for system_key in ['data_flow', 'documentation', 'execution']:
|
||||
for system_key in ["data_flow", "documentation", "execution"]:
|
||||
self.components[system_key] = {}
|
||||
for comp_key, comp_value in comps.get(system_key, {}).items():
|
||||
self.components[system_key][comp_key] = ComponentConfig(**comp_value)
|
||||
@@ -97,13 +99,15 @@ class ConfigLoader:
|
||||
return sys
|
||||
return None
|
||||
|
||||
def get_component(self, system_key: str, component_key: str) -> Optional[ComponentConfig]:
|
||||
def get_component(
|
||||
self, system_key: str, component_key: str
|
||||
) -> Optional[ComponentConfig]:
|
||||
"""Get component config"""
|
||||
return self.components.get(system_key, {}).get(component_key)
|
||||
|
||||
def get_shared_component(self, key: str) -> Optional[ComponentConfig]:
|
||||
"""Get shared component config"""
|
||||
return self.components.get('shared', {}).get(key)
|
||||
return self.components.get("shared", {}).get(key)
|
||||
|
||||
|
||||
def load_config(config_path: str | Path) -> ConfigLoader:
|
||||
@@ -115,6 +119,7 @@ def load_config(config_path: str | Path) -> ConfigLoader:
|
||||
if __name__ == "__main__":
|
||||
# Test with pawprint config
|
||||
import sys
|
||||
|
||||
config_path = Path(__file__).parent.parent / "pawprint.config.json"
|
||||
|
||||
loader = load_config(config_path)
|
||||
@@ -126,5 +131,5 @@ if __name__ == "__main__":
|
||||
print(f" {sys.icon} {sys.title} ({sys.name}) - {sys.tagline}")
|
||||
|
||||
print(f"\nShared Components:")
|
||||
for key, comp in loader.components['shared'].items():
|
||||
for key, comp in loader.components["shared"].items():
|
||||
print(f" {comp.name} - {comp.description}")
|
||||
|
||||
Reference in New Issue
Block a user