feat(PORT-004A): add workspace bootstrap and scoped settings
This commit is contained in:
@@ -222,12 +222,13 @@ class PortfolioRepository:
|
||||
|
||||
CONFIG_PATH = Path("data/portfolio_config.json")
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.CONFIG_PATH.parent.mkdir(parents=True, exist_ok=True)
|
||||
def __init__(self, config_path: Path | None = None) -> None:
|
||||
self.config_path = config_path or self.CONFIG_PATH
|
||||
self.config_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
def save(self, config: PortfolioConfig) -> None:
|
||||
"""Save configuration to disk."""
|
||||
with open(self.CONFIG_PATH, "w") as f:
|
||||
with open(self.config_path, "w") as f:
|
||||
json.dump(config.to_dict(), f, indent=2)
|
||||
|
||||
def load(self) -> PortfolioConfig:
|
||||
@@ -235,13 +236,13 @@ class PortfolioRepository:
|
||||
|
||||
Returns default configuration if file doesn't exist.
|
||||
"""
|
||||
if not self.CONFIG_PATH.exists():
|
||||
if not self.config_path.exists():
|
||||
default = PortfolioConfig()
|
||||
self.save(default)
|
||||
return default
|
||||
|
||||
try:
|
||||
with open(self.CONFIG_PATH) as f:
|
||||
with open(self.config_path) as f:
|
||||
data = json.load(f)
|
||||
return PortfolioConfig.from_dict(data)
|
||||
except (json.JSONDecodeError, ValueError) as e:
|
||||
|
||||
Reference in New Issue
Block a user