halib 0.1.19__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.
- {halib-0.1.19/halib.egg-info → halib-0.1.21}/PKG-INFO +5 -1
- {halib-0.1.19 → halib-0.1.21}/README.md +4 -0
- {halib-0.1.19 → halib-0.1.21}/halib/__init__.py +20 -2
- halib-0.1.21/halib/filetype/yamlfile.py +65 -0
- {halib-0.1.19 → halib-0.1.21/halib.egg-info}/PKG-INFO +5 -1
- {halib-0.1.19 → halib-0.1.21}/halib.egg-info/SOURCES.txt +1 -0
- {halib-0.1.19 → halib-0.1.21}/halib.egg-info/requires.txt +2 -0
- {halib-0.1.19 → halib-0.1.21}/setup.py +1 -1
- {halib-0.1.19 → halib-0.1.21}/.gitignore +0 -0
- {halib-0.1.19 → halib-0.1.21}/GDriveFolder.txt +0 -0
- {halib-0.1.19 → halib-0.1.21}/LICENSE.txt +0 -0
- {halib-0.1.19 → halib-0.1.21}/guide_publish_pip.pdf +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/filetype/__init__.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/filetype/csvfile.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/filetype/jsonfile.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/filetype/textfile.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/filetype/videofile.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/listop.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/online/__init__.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/online/gdrive.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/online/gdrive_mkdir.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/online/gdrive_test.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/online/projectmake.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/plot.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/sys/__init__.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/sys/cmd.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib/sys/filesys.py +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib.egg-info/dependency_links.txt +0 -0
- {halib-0.1.19 → halib-0.1.21}/halib.egg-info/top_level.txt +0 -0
- {halib-0.1.19 → 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.
|
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)
|
@@ -15,12 +15,18 @@ __all__ = [
|
|
15
15
|
"console",
|
16
16
|
"console_log",
|
17
17
|
"ConsoleLog",
|
18
|
-
"re"
|
18
|
+
"re",
|
19
|
+
"now_str",
|
20
|
+
"omegaconf",
|
21
|
+
"OmegaConf",
|
22
|
+
"DictConfig",
|
23
|
+
"load_yaml",
|
19
24
|
]
|
20
25
|
|
21
26
|
import numpy as np
|
22
27
|
import pandas as pd
|
23
28
|
from .filetype import *
|
29
|
+
from .filetype.yamlfile import load_yaml
|
24
30
|
from .sys import cmd
|
25
31
|
from .sys import filesys as fs
|
26
32
|
|
@@ -35,14 +41,23 @@ from tqdm import tqdm
|
|
35
41
|
import matplotlib.pyplot as plt
|
36
42
|
import re
|
37
43
|
import arrow
|
44
|
+
import omegaconf
|
45
|
+
from omegaconf import OmegaConf
|
46
|
+
from omegaconf.dictconfig import DictConfig
|
38
47
|
|
39
48
|
console = Console()
|
40
49
|
|
50
|
+
|
41
51
|
def now_str(sep_date_time="."):
|
42
|
-
assert sep_date_time in [
|
52
|
+
assert sep_date_time in [
|
53
|
+
".",
|
54
|
+
"_",
|
55
|
+
"-",
|
56
|
+
], "sep_date_time must be one of '.', '_', or '-'"
|
43
57
|
now_string = arrow.now().format(f"YYYYMMDD{sep_date_time}HHmmss")
|
44
58
|
return now_string
|
45
59
|
|
60
|
+
|
46
61
|
def norm_str(in_str):
|
47
62
|
# Replace one or more whitespace characters with a single underscore
|
48
63
|
norm_string = re.sub(r"\s+", "_", in_str)
|
@@ -50,6 +65,7 @@ def norm_str(in_str):
|
|
50
65
|
norm_string = norm_string.strip()
|
51
66
|
return norm_string
|
52
67
|
|
68
|
+
|
53
69
|
def console_rule(msg, do_norm_msg=True, is_end_tag=False):
|
54
70
|
msg = norm_str(msg) if do_norm_msg else msg
|
55
71
|
if is_end_tag:
|
@@ -57,6 +73,7 @@ def console_rule(msg, do_norm_msg=True, is_end_tag=False):
|
|
57
73
|
else:
|
58
74
|
console.rule(f"<{msg}>")
|
59
75
|
|
76
|
+
|
60
77
|
def console_log(func):
|
61
78
|
def wrapper(*args, **kwargs):
|
62
79
|
console_rule(func.__name__)
|
@@ -66,6 +83,7 @@ def console_log(func):
|
|
66
83
|
|
67
84
|
return wrapper
|
68
85
|
|
86
|
+
|
69
87
|
class ConsoleLog:
|
70
88
|
def __init__(self, message):
|
71
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.
|
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)
|
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
|
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
|