11import logging
2- import os
2+ from pathlib import Path
33from typing import List
4-
54import typer
65import yaml
76from pydantic import BaseModel , ValidationError
109
1110logger = logging .getLogger (__name__ )
1211
13- CONFIG_PATH = os .path .expanduser ("~/.config/docbinder/config.yaml" )
14-
12+ CONFIG_PATH = Path ("~/.config/docbinder/config.yaml" ).expanduser ()
1513
1614class Config (BaseModel ):
1715 """Main configuration model that holds a list of all provider configs."""
18-
1916 providers : List [ServiceUnion ]
2017
2118
2219def load_config () -> Config :
23- if not os . path . exists (CONFIG_PATH ):
20+ if not CONFIG_PATH . exists ():
2421 typer .echo (
2522 f"Config file not found at { CONFIG_PATH } . Please run 'docbinder setup' first."
2623 )
2724 raise typer .Exit (code = 1 )
25+
2826 with open (CONFIG_PATH , "r" ) as f :
2927 config_data = yaml .safe_load (f )
28+
3029 provider_registry = get_provider_registry ()
3130 config_to_add = []
3231 for config in config_data .get ("providers" , []):
@@ -45,7 +44,8 @@ def load_config() -> Config:
4544
4645
4746def save_config (config : Config ):
48- os .makedirs (os .path .dirname (CONFIG_PATH ), exist_ok = True )
47+ CONFIG_PATH .parent .mkdir (parents = True , exist_ok = True )
48+
4949 with open (CONFIG_PATH , "w" ) as f :
5050 yaml .dump (config .model_dump (), f , default_flow_style = False )
5151 typer .echo (f"Config saved to { CONFIG_PATH } " )
0 commit comments