88import sys
99import tomli
1010from pathlib import Path
11- from pydantic import ValidationError
1211from typing import TYPE_CHECKING
1312
1413if TYPE_CHECKING :
@@ -52,8 +51,15 @@ def _ensure_chipflow_root():
5251 return _ensure_chipflow_root .root #type: ignore
5352
5453
54+ def _get_src_loc (src_loc_at = 0 ):
55+ frame = sys ._getframe (1 + src_loc_at )
56+ return (frame .f_code .co_filename , frame .f_lineno )
57+
58+
59+
5560def _parse_config () -> 'Config' :
5661 """Parse the chipflow.toml configuration file."""
62+ from .config import _parse_config_file
5763 chipflow_root = _ensure_chipflow_root ()
5864 config_file = Path (chipflow_root ) / "chipflow.toml"
5965 try :
@@ -62,29 +68,3 @@ def _parse_config() -> 'Config':
6268 raise ChipFlowError (f"Config file not found. I expected to find it at { config_file } " )
6369 except tomli .TOMLDecodeError as e :
6470 raise ChipFlowError (f"TOML Error found when loading { config_file } : { e .msg } at line { e .lineno } , column { e .colno } " )
65-
66-
67- def _parse_config_file (config_file ) -> 'Config' :
68- """Parse a specific chipflow.toml configuration file."""
69-
70- with open (config_file , "rb" ) as f :
71- config_dict = tomli .load (f )
72-
73- try :
74- # Validate with Pydantic
75- return Config .model_validate (config_dict ) # Just validate the config_dict
76- except ValidationError as e :
77- # Format Pydantic validation errors in a user-friendly way
78- error_messages = []
79- for error in e .errors ():
80- location = "." .join (str (loc ) for loc in error ["loc" ])
81- message = error ["msg" ]
82- error_messages .append (f"Error at '{ location } ': { message } " )
83-
84- error_str = "\n " .join (error_messages )
85- raise ChipFlowError (f"Validation error in chipflow.toml:\n { error_str } " )
86-
87- def _get_src_loc (src_loc_at = 0 ):
88- frame = sys ._getframe (1 + src_loc_at )
89- return (frame .f_code .co_filename , frame .f_lineno )
90-
0 commit comments