hungerlib 3.2.dev2__py3-none-any.whl → 3.2.dev3__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- hungerlib/configloader.py +29 -7
- {hungerlib-3.2.dev2.dist-info → hungerlib-3.2.dev3.dist-info}/METADATA +1 -1
- {hungerlib-3.2.dev2.dist-info → hungerlib-3.2.dev3.dist-info}/RECORD +6 -6
- {hungerlib-3.2.dev2.dist-info → hungerlib-3.2.dev3.dist-info}/WHEEL +0 -0
- {hungerlib-3.2.dev2.dist-info → hungerlib-3.2.dev3.dist-info}/licenses/LICENSE +0 -0
- {hungerlib-3.2.dev2.dist-info → hungerlib-3.2.dev3.dist-info}/top_level.txt +0 -0
hungerlib/configloader.py
CHANGED
|
@@ -2,7 +2,7 @@ import inspect
|
|
|
2
2
|
import os
|
|
3
3
|
import yaml
|
|
4
4
|
import importlib
|
|
5
|
-
from dataclasses import fields
|
|
5
|
+
from dataclasses import fields, MISSING
|
|
6
6
|
|
|
7
7
|
class Namespace:
|
|
8
8
|
def __init__(self):
|
|
@@ -32,6 +32,16 @@ def load_yaml(path):
|
|
|
32
32
|
with open(path, "r") as f:
|
|
33
33
|
return yaml.safe_load(f) or {}
|
|
34
34
|
|
|
35
|
+
def convert_value(value, annotation):
|
|
36
|
+
if annotation is int:
|
|
37
|
+
return int(value)
|
|
38
|
+
if annotation is float:
|
|
39
|
+
return float(value)
|
|
40
|
+
if annotation is bool:
|
|
41
|
+
# YAML already parses true/false correctly
|
|
42
|
+
return bool(value)
|
|
43
|
+
return value
|
|
44
|
+
|
|
35
45
|
def loadConfig(path, default_path, schema):
|
|
36
46
|
abs_path = os.path.abspath(path)
|
|
37
47
|
os.makedirs(os.path.dirname(abs_path), exist_ok=True)
|
|
@@ -50,18 +60,30 @@ def loadConfig(path, default_path, schema):
|
|
|
50
60
|
f.write("# No default config found.\n")
|
|
51
61
|
|
|
52
62
|
raw = load_yaml(abs_path)
|
|
53
|
-
|
|
54
63
|
values = {}
|
|
55
64
|
|
|
65
|
+
mode = getattr(schema, "__mode__", None)
|
|
66
|
+
|
|
56
67
|
for f in fields(schema):
|
|
57
|
-
|
|
58
|
-
if
|
|
68
|
+
# --- OLD SYSTEM SUPPORT (yaml_key) ---
|
|
69
|
+
yaml_path = f.metadata.get("yaml_key") if f.metadata else None
|
|
70
|
+
if yaml_path:
|
|
71
|
+
value = deep_get(raw, yaml_path)
|
|
72
|
+
if value is not None:
|
|
73
|
+
values[f.name] = convert_value(value, f.type)
|
|
59
74
|
continue
|
|
60
75
|
|
|
61
|
-
|
|
62
|
-
|
|
76
|
+
# --- NEW SYSTEM: mode="config" + string defaults ---
|
|
77
|
+
default = f.default
|
|
78
|
+
if mode == "config" and isinstance(default, str):
|
|
79
|
+
yaml_path = default
|
|
80
|
+
value = deep_get(raw, yaml_path)
|
|
81
|
+
if value is not None:
|
|
82
|
+
values[f.name] = convert_value(value, f.type)
|
|
63
83
|
continue
|
|
64
84
|
|
|
65
|
-
|
|
85
|
+
# --- FALLBACK: use dataclass default ---
|
|
86
|
+
if default is not MISSING:
|
|
87
|
+
values[f.name] = default
|
|
66
88
|
|
|
67
89
|
return schema(**values)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
hungerlib/__init__.py,sha256=CExLyU07UUVzaERKZnkzNilUz_FnFE9zRaQg_8qecKo,2189
|
|
2
|
-
hungerlib/configloader.py,sha256=
|
|
2
|
+
hungerlib/configloader.py,sha256=H2WXVcgUbN-F9961eshArMWFUc6WErHacXPu6TuDIlY,2599
|
|
3
3
|
hungerlib/datamap.py,sha256=lEaS5mAweNE0sQA-9eRW1F9QbHoUADPhhASpT29NTvs,2164
|
|
4
4
|
hungerlib/messagerouter.py,sha256=1-4KeUT6AgTF0F53n3BtWt0ch0lnHHXYPOWvRtvUVKY,4344
|
|
5
5
|
hungerlib/panel.py,sha256=LljDy3FZoabWotdrNhN89xHd2VcvbiQDshtZgMa0g08,2013
|
|
@@ -17,8 +17,8 @@ hungerlib/utils/__init__.py,sha256=xyUldIwkVopZrp0Yp5g18vqGDUp3OOT4KknntLU4oes,5
|
|
|
17
17
|
hungerlib/utils/colormaps.py,sha256=88eIDSI1hZYbtXmd7XujgmR1nhOXAkyB8ospQTqSHns,1240
|
|
18
18
|
hungerlib/utils/time.py,sha256=lhLHMkL5NEP9f7j5k24k5brr1ZvAL22t07eV2rxTZ50,2354
|
|
19
19
|
hungerlib/utils/utils.py,sha256=rGVXiK-ZaN1riNL_1QHKJZdOAX53vGlSDUzEP1Aqle4,1404
|
|
20
|
-
hungerlib-3.2.
|
|
21
|
-
hungerlib-3.2.
|
|
22
|
-
hungerlib-3.2.
|
|
23
|
-
hungerlib-3.2.
|
|
24
|
-
hungerlib-3.2.
|
|
20
|
+
hungerlib-3.2.dev3.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
21
|
+
hungerlib-3.2.dev3.dist-info/METADATA,sha256=JIit-rWDhUufCxw43c9pOXT_MLw43FdoQObSNl-ef6c,1535
|
|
22
|
+
hungerlib-3.2.dev3.dist-info/WHEEL,sha256=aeYiig01lYGDzBgS8HxWXOg3uV61G9ijOsup-k9o1sk,91
|
|
23
|
+
hungerlib-3.2.dev3.dist-info/top_level.txt,sha256=uHBMIM8b2Gt6daNkDF4uw-M2Hm2IpIVw1jOK9wC0fNQ,10
|
|
24
|
+
hungerlib-3.2.dev3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|