Spaces:
Running
Running
Z User commited on
Commit ·
5da5903
1
Parent(s): 21d566d
fix: use PyYAML for config parsing to read nested values correctly
Browse files
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
|
| 89 |
-
cfg: dict = {}
|
| 90 |
try:
|
|
|
|
| 91 |
with open(CONFIG_FILE) as f:
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
if
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
cfg[k] = v
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
except FileNotFoundError:
|
| 111 |
-
|
| 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:
|