halib 0.1.20__tar.gz → 0.1.21__tar.gz

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.
Files changed (30) hide show
  1. {halib-0.1.20/halib.egg-info → halib-0.1.21}/PKG-INFO +5 -1
  2. {halib-0.1.20 → halib-0.1.21}/README.md +4 -0
  3. {halib-0.1.20 → halib-0.1.21}/halib/__init__.py +18 -1
  4. halib-0.1.21/halib/filetype/yamlfile.py +65 -0
  5. {halib-0.1.20 → halib-0.1.21/halib.egg-info}/PKG-INFO +5 -1
  6. {halib-0.1.20 → halib-0.1.21}/halib.egg-info/SOURCES.txt +1 -0
  7. {halib-0.1.20 → halib-0.1.21}/halib.egg-info/requires.txt +2 -0
  8. {halib-0.1.20 → halib-0.1.21}/setup.py +1 -1
  9. {halib-0.1.20 → halib-0.1.21}/.gitignore +0 -0
  10. {halib-0.1.20 → halib-0.1.21}/GDriveFolder.txt +0 -0
  11. {halib-0.1.20 → halib-0.1.21}/LICENSE.txt +0 -0
  12. {halib-0.1.20 → halib-0.1.21}/guide_publish_pip.pdf +0 -0
  13. {halib-0.1.20 → halib-0.1.21}/halib/filetype/__init__.py +0 -0
  14. {halib-0.1.20 → halib-0.1.21}/halib/filetype/csvfile.py +0 -0
  15. {halib-0.1.20 → halib-0.1.21}/halib/filetype/jsonfile.py +0 -0
  16. {halib-0.1.20 → halib-0.1.21}/halib/filetype/textfile.py +0 -0
  17. {halib-0.1.20 → halib-0.1.21}/halib/filetype/videofile.py +0 -0
  18. {halib-0.1.20 → halib-0.1.21}/halib/listop.py +0 -0
  19. {halib-0.1.20 → halib-0.1.21}/halib/online/__init__.py +0 -0
  20. {halib-0.1.20 → halib-0.1.21}/halib/online/gdrive.py +0 -0
  21. {halib-0.1.20 → halib-0.1.21}/halib/online/gdrive_mkdir.py +0 -0
  22. {halib-0.1.20 → halib-0.1.21}/halib/online/gdrive_test.py +0 -0
  23. {halib-0.1.20 → halib-0.1.21}/halib/online/projectmake.py +0 -0
  24. {halib-0.1.20 → halib-0.1.21}/halib/plot.py +0 -0
  25. {halib-0.1.20 → halib-0.1.21}/halib/sys/__init__.py +0 -0
  26. {halib-0.1.20 → halib-0.1.21}/halib/sys/cmd.py +0 -0
  27. {halib-0.1.20 → halib-0.1.21}/halib/sys/filesys.py +0 -0
  28. {halib-0.1.20 → halib-0.1.21}/halib.egg-info/dependency_links.txt +0 -0
  29. {halib-0.1.20 → halib-0.1.21}/halib.egg-info/top_level.txt +0 -0
  30. {halib-0.1.20 → halib-0.1.21}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: halib
3
- Version: 0.1.20
3
+ Version: 0.1.21
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -15,6 +15,10 @@ License-File: LICENSE.txt
15
15
 
16
16
  Helper package for coding and automation
17
17
 
18
+ **Version 0.1.21**
19
+
20
+ + using `networkx` and `omegaconf` to allow yaml file inheritance and override
21
+ ---
18
22
  **Version 0.1.15**
19
23
 
20
24
  + `__init__.py`: add common logging library; also `console_log` decorator to log function (start and end)
@@ -1,5 +1,9 @@
1
1
  Helper package for coding and automation
2
2
 
3
+ **Version 0.1.21**
4
+
5
+ + using `networkx` and `omegaconf` to allow yaml file inheritance and override
6
+ ---
3
7
  **Version 0.1.15**
4
8
 
5
9
  + `__init__.py`: add common logging library; also `console_log` decorator to log function (start and end)
@@ -17,11 +17,16 @@ __all__ = [
17
17
  "ConsoleLog",
18
18
  "re",
19
19
  "now_str",
20
+ "omegaconf",
21
+ "OmegaConf",
22
+ "DictConfig",
23
+ "load_yaml",
20
24
  ]
21
25
 
22
26
  import numpy as np
23
27
  import pandas as pd
24
28
  from .filetype import *
29
+ from .filetype.yamlfile import load_yaml
25
30
  from .sys import cmd
26
31
  from .sys import filesys as fs
27
32
 
@@ -36,14 +41,23 @@ from tqdm import tqdm
36
41
  import matplotlib.pyplot as plt
37
42
  import re
38
43
  import arrow
44
+ import omegaconf
45
+ from omegaconf import OmegaConf
46
+ from omegaconf.dictconfig import DictConfig
39
47
 
40
48
  console = Console()
41
49
 
50
+
42
51
  def now_str(sep_date_time="."):
43
- assert sep_date_time in [".", "_", "-"], "sep_date_time must be one of '.', '_', or '-'"
52
+ assert sep_date_time in [
53
+ ".",
54
+ "_",
55
+ "-",
56
+ ], "sep_date_time must be one of '.', '_', or '-'"
44
57
  now_string = arrow.now().format(f"YYYYMMDD{sep_date_time}HHmmss")
45
58
  return now_string
46
59
 
60
+
47
61
  def norm_str(in_str):
48
62
  # Replace one or more whitespace characters with a single underscore
49
63
  norm_string = re.sub(r"\s+", "_", in_str)
@@ -51,6 +65,7 @@ def norm_str(in_str):
51
65
  norm_string = norm_string.strip()
52
66
  return norm_string
53
67
 
68
+
54
69
  def console_rule(msg, do_norm_msg=True, is_end_tag=False):
55
70
  msg = norm_str(msg) if do_norm_msg else msg
56
71
  if is_end_tag:
@@ -58,6 +73,7 @@ def console_rule(msg, do_norm_msg=True, is_end_tag=False):
58
73
  else:
59
74
  console.rule(f"<{msg}>")
60
75
 
76
+
61
77
  def console_log(func):
62
78
  def wrapper(*args, **kwargs):
63
79
  console_rule(func.__name__)
@@ -67,6 +83,7 @@ def console_log(func):
67
83
 
68
84
  return wrapper
69
85
 
86
+
70
87
  class ConsoleLog:
71
88
  def __init__(self, message):
72
89
  self.message = message
@@ -0,0 +1,65 @@
1
+ import time
2
+ import networkx as nx
3
+ from rich import inspect
4
+ from rich.pretty import pprint
5
+ from omegaconf import OmegaConf
6
+ from rich.console import Console
7
+ from argparse import ArgumentParser
8
+
9
+ console = Console()
10
+
11
+ def _load_yaml_recursively(
12
+ yaml_file, yaml_files=[], share_nx_graph=nx.DiGraph(), log_info=False
13
+ ):
14
+ conf = OmegaConf.load(yaml_file)
15
+ yaml_files.append(yaml_file)
16
+ if "__base__" in conf:
17
+ parent = conf["__base__"]
18
+ if isinstance(parent, str):
19
+ parent = [parent]
20
+ for p in parent:
21
+ edge = (yaml_file, p)
22
+ share_nx_graph.add_edge(*edge)
23
+ for cycle in nx.simple_cycles(share_nx_graph):
24
+ assert False, f"Cyclic dependency detected: {cycle}"
25
+ # update conf with parent; BY loading parent and merging with conf (the child)
26
+ conf = OmegaConf.merge(
27
+ _load_yaml_recursively(p, yaml_files, share_nx_graph), conf
28
+ )
29
+ if log_info:
30
+ console.rule()
31
+ console.print(f"current yaml_file: {yaml_file}")
32
+ inspect(yaml_files)
33
+ pprint(OmegaConf.to_container(conf, resolve=True))
34
+ time.sleep(1)
35
+ return conf
36
+
37
+
38
+ def load_yaml(yaml_file, to_dict=False, log_info=False):
39
+ yaml_files = []
40
+ share_nx_graph = nx.DiGraph()
41
+ omgconf = _load_yaml_recursively(yaml_file, yaml_files=yaml_files, share_nx_graph=share_nx_graph, log_info=log_info)
42
+
43
+ if to_dict:
44
+ return OmegaConf.to_container(omgconf, resolve=True)
45
+ else:
46
+ return omgconf
47
+
48
+
49
+ def parse_args():
50
+ parser = ArgumentParser(
51
+ description="desc text")
52
+ parser.add_argument(
53
+ "-cfg", "--cfg", type=str, help="cfg file", default="cfg__default.yaml")
54
+ return parser.parse_args()
55
+
56
+
57
+ def main():
58
+ args = parse_args()
59
+ cfg_file = args.cfg
60
+ cfg = load_yaml(cfg_file, to_dict=True)
61
+ console.rule()
62
+ pprint(cfg)
63
+
64
+ if __name__ == "__main__":
65
+ main()
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: halib
3
- Version: 0.1.20
3
+ Version: 0.1.21
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -15,6 +15,10 @@ License-File: LICENSE.txt
15
15
 
16
16
  Helper package for coding and automation
17
17
 
18
+ **Version 0.1.21**
19
+
20
+ + using `networkx` and `omegaconf` to allow yaml file inheritance and override
21
+ ---
18
22
  **Version 0.1.15**
19
23
 
20
24
  + `__init__.py`: add common logging library; also `console_log` decorator to log function (start and end)
@@ -17,6 +17,7 @@ halib/filetype/csvfile.py
17
17
  halib/filetype/jsonfile.py
18
18
  halib/filetype/textfile.py
19
19
  halib/filetype/videofile.py
20
+ halib/filetype/yamlfile.py
20
21
  halib/online/__init__.py
21
22
  halib/online/gdrive.py
22
23
  halib/online/gdrive_mkdir.py
@@ -2,3 +2,5 @@ rich
2
2
  tqdm
3
3
  tabulate
4
4
  loguru
5
+ omegaconf
6
+ networkx
@@ -8,7 +8,7 @@ with open("requirements.txt") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="halib",
11
- version="0.1.20",
11
+ version="0.1.21",
12
12
  author="Hoang Van Ha",
13
13
  author_email="hoangvanhauit@gmail.com",
14
14
  description="Small library for common tasks",
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes