Files
vibemake-pcb-studio/backend/api/app/config.py
T
2026-11-10 19:04:27 +08:00

26 lines
1.2 KiB
Python

from dataclasses import dataclass
from pathlib import Path
import os
@dataclass
class Settings:
root: Path
pack: Path
mode: str = 'simulation'
simulator: Path | None = None
origins: tuple = ('http://127.0.0.1:5173','http://localhost:5173','http://127.0.0.1:8000')
command_timeout: int = 21600
@classmethod
def env(cls):
base=Path(__file__).resolve().parents[2]
mode=os.getenv('AI_PCB_MODE','simulation')
if mode not in {'simulation','assessment','real'}:raise ValueError('Invalid AI_PCB_MODE')
simulator=os.getenv('AI_PCB_SIMULATOR')
return cls(Path(os.getenv('AI_PCB_API_DATA',str(Path.home()/'.local/share/vibemake-pcb'))).resolve(),
Path(os.getenv('AI_PCB_PACK_DIR',str(base/'easyeda_backend'))).resolve(),mode,
Path(simulator).resolve() if simulator else None,
tuple(os.getenv('AI_PCB_ALLOWED_ORIGINS','http://127.0.0.1:5173,http://localhost:5173,http://127.0.0.1:8000').split(',')),
command_timeout=min(172800,max(300,int(os.getenv('AI_PCB_COMMAND_TIMEOUT','21600')))))
@property
def core_root(self):return self.root/'core'