Z User commited on
Commit
5da5903
·
1 Parent(s): 21d566d

fix: use PyYAML for config parsing to read nested values correctly

Browse files
Files changed (1) hide show
  1. entry.py +20 -21
entry.py CHANGED
@@ -85,31 +85,30 @@ def _load_env() -> dict[str, str]:
85
 
86
 
87
  def _load_config() -> dict:
88
- """Read config.yaml into dict (simple parser)."""
89
- cfg: dict = {}
90
  try:
 
91
  with open(CONFIG_FILE) as f:
92
- current_section = None
93
- for line in f:
94
- stripped = line.strip()
95
- if not stripped or stripped.startswith("#"):
96
- continue
97
- # Check for section headers
98
- if ":" in stripped and not line.startswith(" "):
99
- k, _, v = stripped.partition(":")
100
- k = k.strip()
101
- v = v.strip()
102
- if v:
103
- if current_section:
104
- cfg[current_section + "." + k] = v
105
- else:
106
  cfg[k] = v
107
- # Check for nested section
108
- if stripped.endswith(":") and not stripped.startswith(" ") and ":" not in stripped[:-1]:
109
- current_section = stripped[:-1].strip()
110
  except FileNotFoundError:
111
- pass
112
- return cfg
113
 
114
 
115
  def _get_sessions_count() -> int:
 
85
 
86
 
87
  def _load_config() -> dict:
88
+ """Read config.yaml into dict using PyYAML."""
 
89
  try:
90
+ import yaml
91
  with open(CONFIG_FILE) as f:
92
+ return yaml.safe_load(f) or {}
93
+ except ImportError:
94
+ # Fallback: simple flat parser (no nested support)
95
+ cfg: dict = {}
96
+ try:
97
+ with open(CONFIG_FILE) as f:
98
+ for line in f:
99
+ stripped = line.strip()
100
+ if not stripped or stripped.startswith("#"):
101
+ continue
102
+ if ":" in stripped and not line.startswith(" "):
103
+ k, _, v = stripped.partition(":")
104
+ k, v = k.strip(), v.strip()
105
+ if v:
106
  cfg[k] = v
107
+ except FileNotFoundError:
108
+ pass
109
+ return cfg
110
  except FileNotFoundError:
111
+ return {}
 
112
 
113
 
114
  def _get_sessions_count() -> int: