66from pathlib import Path
77from typing import Any , Optional
88
9+
910@dataclass
1011class AppConfig :
1112 """Application configuration."""
13+
1214 app_name : str
1315 environment : str
1416 debug : bool
1517 log_level : str
16-
18+
1719 @classmethod
1820 def from_env (cls ) -> "AppConfig" :
1921 """Create configuration from environment variables.
20-
22+
2123 Returns:
2224 AppConfig: Application configuration instance
2325 """
@@ -28,35 +30,39 @@ def from_env(cls) -> "AppConfig":
2830 log_level = os .getenv ("LOG_LEVEL" , "INFO" ),
2931 )
3032
33+
3134def load_json_config (path : Path ) -> dict [str , Any ]:
3235 """Load configuration from JSON file.
33-
36+
3437 Args:
3538 path: Path to JSON configuration file
36-
39+
3740 Returns:
3841 dict[str, Any]: Configuration dictionary
39-
42+
4043 Raises:
4144 FileNotFoundError: If configuration file doesn't exist
4245 json.JSONDecodeError: If configuration file is invalid JSON
4346 """
4447 if not path .exists ():
4548 raise FileNotFoundError (f"Configuration file not found: { path } " )
46-
49+
4750 with path .open () as f :
4851 return json .load (f )
4952
53+
5054class ConfigurationError (Exception ):
5155 """Base class for configuration errors."""
56+
5257 pass
5358
59+
5460def get_config_path (config_name : str ) -> Path :
5561 """Get configuration file path.
56-
62+
5763 Args:
5864 config_name: Name of the configuration file
59-
65+
6066 Returns:
6167 Path: Path to configuration file
6268 """
@@ -66,10 +72,10 @@ def get_config_path(config_name: str) -> Path:
6672 Path ("~/.config/template-python" ), # User config directory
6773 Path ("/etc/template-python" ), # System config directory
6874 ]
69-
75+
7076 for location in locations :
7177 path = location .expanduser () / f"{ config_name } .json"
7278 if path .exists ():
7379 return path
74-
75- return locations [0 ].expanduser () / f"{ config_name } .json"
80+
81+ return locations [0 ].expanduser () / f"{ config_name } .json"
0 commit comments