-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconfig.py
More file actions
40 lines (29 loc) · 1003 Bytes
/
config.py
File metadata and controls
40 lines (29 loc) · 1003 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from __future__ import annotations
import json
from pathlib import Path
from typing import Any
DEFAULT_CONFIG_PATH = "config.json"
class ConfigError(Exception):
pass
def load_config(path: str | Path) -> dict[str, Any]:
config_path = Path(path)
if not config_path.exists():
raise ConfigError(f"Config file not found: {config_path}")
try:
data = json.loads(config_path.read_text(encoding="utf-8"))
except json.JSONDecodeError as exc:
raise ConfigError(f"Invalid JSON in config file: {config_path}") from exc
required_keys = [
"watch_dir",
"processed_dir",
"archive_dir",
"error_dir",
"log_dir",
"rules",
]
missing = [key for key in required_keys if key not in data]
if missing:
raise ConfigError(f"Missing required config keys: {', '.join(missing)}")
if not isinstance(data.get("rules"), list):
raise ConfigError("Config key 'rules' must be a list")
return data