halib 0.1.52__py3-none-any.whl → 0.1.53__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.
@@ -0,0 +1,39 @@
1
+ import yaml
2
+ from typing import Any
3
+ from rich.pretty import pprint
4
+ from ..filetype import yamlfile
5
+ # from halib.filetype import yamlfile
6
+ from dataclasses import make_dataclass
7
+
8
+ def dict_to_dataclass(name: str, data: dict):
9
+ fields = []
10
+ values = {}
11
+
12
+ for key, value in data.items():
13
+ if isinstance(value, dict):
14
+ sub_dc = dict_to_dataclass(key.capitalize(), value)
15
+ fields.append((key, type(sub_dc)))
16
+ values[key] = sub_dc
17
+ else:
18
+ field_type = type(value) if value is not None else Any
19
+ fields.append((key, field_type))
20
+ values[key] = value
21
+
22
+ DC = make_dataclass(name.capitalize(), fields)
23
+ return DC(**values)
24
+
25
+ def yaml_to_dataclass(name: str, yaml_str: str):
26
+ data = yaml.safe_load(yaml_str)
27
+ return dict_to_dataclass(name, data)
28
+
29
+ def yamlfile_to_dataclass(name: str, file_path: str):
30
+ data_dict = yamlfile.load_yaml(file_path, to_dict=True)
31
+ if "__base__" in data_dict:
32
+ del data_dict["__base__"]
33
+ return dict_to_dataclass(name, data_dict)
34
+
35
+ if __name__ == "__main__":
36
+ cfg = yamlfile_to_dataclass("Config", "test/dataclass_util_test_cfg.yaml")
37
+
38
+ # ! NOTICE: after print out this dataclass, we can copy the output and paste it into CHATGPT to generate a list of needed dataclass classes using `from dataclass_wizard import YAMLWizard`
39
+ pprint(cfg)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: halib
3
- Version: 0.1.52
3
+ Version: 0.1.53
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -41,9 +41,14 @@ Requires-Dist: timebudget
41
41
  Requires-Dist: tqdm
42
42
  Requires-Dist: tube-dl
43
43
  Requires-Dist: wandb
44
+ Requires-Dist: dataclass-wizard
44
45
 
45
46
  Helper package for coding and automation
46
47
 
48
+ **Version 0.1.53**
49
+
50
+ + add `util/dataclass_util` to help dynamically create `dataclass` classes from dictionary or YAML file, including support for nested dataclasses. From there, we can use `dataclass_wizard` to create a list of `dataclass` classes with the help from ChatGPT.
51
+
47
52
  **Version 0.1.52**
48
53
 
49
54
  + add `research/perftb` module to allow creating and managing performance tables for experiments, including filtering by datasets, metrics, and experiments.
@@ -41,10 +41,11 @@ halib/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
41
41
  halib/system/cmd.py,sha256=b2x7JPcNnFjLGheIESVYvqAb-w2UwBM1PAwYxMZ5YjA,228
42
42
  halib/system/filesys.py,sha256=ERpnELLDKJoTIIKf-AajgkY62nID4qmqmX5TkE95APU,2931
43
43
  halib/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
44
+ halib/utils/dataclass_util.py,sha256=aD5Ik9BRJzIEyfdlOCHmOddA7TM_TIAfapZfU0vMigE,1414
44
45
  halib/utils/listop.py,sha256=Vpa8_2fI0wySpB2-8sfTBkyi_A4FhoFVVvFiuvW8N64,339
45
46
  halib/utils/tele_noti.py,sha256=-4WXZelCA4W9BroapkRyIdUu9cUVrcJJhegnMs_WpGU,5928
46
- halib-0.1.52.dist-info/LICENSE.txt,sha256=qZssdna4aETiR8znYsShUjidu-U4jUT9Q-EWNlZ9yBQ,1100
47
- halib-0.1.52.dist-info/METADATA,sha256=L7VAgjU0YRRNbpDHXBiN2y0jZIO6jDziiW2rQoBmFaQ,4365
48
- halib-0.1.52.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
49
- halib-0.1.52.dist-info/top_level.txt,sha256=7AD6PLaQTreE0Fn44mdZsoHBe_Zdd7GUmjsWPyQ7I-k,6
50
- halib-0.1.52.dist-info/RECORD,,
47
+ halib-0.1.53.dist-info/LICENSE.txt,sha256=qZssdna4aETiR8znYsShUjidu-U4jUT9Q-EWNlZ9yBQ,1100
48
+ halib-0.1.53.dist-info/METADATA,sha256=TgyMGbS3YvF5Nm7LzNvbAZBp6P4Oc0Tk3cGQY4c6G4I,4675
49
+ halib-0.1.53.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
50
+ halib-0.1.53.dist-info/top_level.txt,sha256=7AD6PLaQTreE0Fn44mdZsoHBe_Zdd7GUmjsWPyQ7I-k,6
51
+ halib-0.1.53.dist-info/RECORD,,
File without changes