halib 0.2.5__py3-none-any.whl → 0.2.6__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.
- halib/filetype/yamlfile.py +6 -14
- halib/system/path.py +32 -11
- {halib-0.2.5.dist-info → halib-0.2.6.dist-info}/METADATA +2 -2
- {halib-0.2.5.dist-info → halib-0.2.6.dist-info}/RECORD +7 -7
- {halib-0.2.5.dist-info → halib-0.2.6.dist-info}/WHEEL +0 -0
- {halib-0.2.5.dist-info → halib-0.2.6.dist-info}/licenses/LICENSE.txt +0 -0
- {halib-0.2.5.dist-info → halib-0.2.6.dist-info}/top_level.txt +0 -0
halib/filetype/yamlfile.py
CHANGED
|
@@ -11,6 +11,7 @@ from ..system.path import *
|
|
|
11
11
|
|
|
12
12
|
console = Console()
|
|
13
13
|
|
|
14
|
+
|
|
14
15
|
def _load_yaml_recursively(
|
|
15
16
|
yaml_file, yaml_files=[], share_nx_graph=nx.DiGraph(), log_info=False
|
|
16
17
|
):
|
|
@@ -53,25 +54,16 @@ def load_yaml(yaml_file, to_dict=False, log_info=False):
|
|
|
53
54
|
else:
|
|
54
55
|
return omgconf
|
|
55
56
|
|
|
57
|
+
|
|
56
58
|
def load_yaml_with_PC_abbr(
|
|
57
|
-
yaml_file,
|
|
59
|
+
yaml_file, abbr_disk_map=ABBR_DISK_MAP
|
|
58
60
|
):
|
|
59
|
-
# current PC abbreviation
|
|
60
|
-
pc_abbr = get_PC_abbr_name()
|
|
61
|
-
|
|
62
|
-
# current plaftform: windows or linux
|
|
63
|
-
current_platform = platform.system().lower()
|
|
64
|
-
|
|
65
|
-
assert pc_abbr in pc_abbr_to_working_disk, f"The is no mapping for {pc_abbr} to <working_disk>"
|
|
66
|
-
|
|
67
|
-
# working disk
|
|
68
|
-
working_disk = pc_abbr_to_working_disk.get(pc_abbr)
|
|
69
|
-
|
|
70
61
|
# load yaml file
|
|
71
62
|
data_dict = load_yaml(yaml_file=yaml_file, to_dict=True)
|
|
72
|
-
|
|
73
63
|
# Normalize paths in the loaded data
|
|
74
|
-
data_dict = normalize_paths(
|
|
64
|
+
data_dict = normalize_paths(
|
|
65
|
+
data_dict, get_working_disk(abbr_disk_map), get_os_platform()
|
|
66
|
+
)
|
|
75
67
|
return data_dict
|
|
76
68
|
|
|
77
69
|
|
halib/system/path.py
CHANGED
|
@@ -2,9 +2,9 @@ from ..common.common import *
|
|
|
2
2
|
from ..filetype import csvfile
|
|
3
3
|
import pandas as pd
|
|
4
4
|
import platform
|
|
5
|
+
import re # <--- [FIX 1] Added missing import
|
|
5
6
|
|
|
6
|
-
|
|
7
|
-
PC_NAME_TO_ABBR = {
|
|
7
|
+
PC_TO_ABBR = {
|
|
8
8
|
"DESKTOP-JQD9K01": "MainPC",
|
|
9
9
|
"DESKTOP-5IRHU87": "MSI_Laptop",
|
|
10
10
|
"DESKTOP-96HQCNO": "4090_SV",
|
|
@@ -12,17 +12,16 @@ PC_NAME_TO_ABBR = {
|
|
|
12
12
|
"DESKTOP-QNS3DNF": "1GPU_SV",
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
ABBR_DISK_MAP = {
|
|
16
16
|
"MainPC": "E:",
|
|
17
17
|
"MSI_Laptop": "D:",
|
|
18
18
|
"4090_SV": "E:",
|
|
19
19
|
"4GPU_SV": "D:",
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
+
|
|
22
23
|
def list_PCs(show=True):
|
|
23
|
-
df = pd.DataFrame(
|
|
24
|
-
list(PC_NAME_TO_ABBR.items()), columns=["PC Name", "Abbreviation"]
|
|
25
|
-
)
|
|
24
|
+
df = pd.DataFrame(list(PC_TO_ABBR.items()), columns=["PC Name", "Abbreviation"])
|
|
26
25
|
if show:
|
|
27
26
|
csvfile.fn_display_df(df)
|
|
28
27
|
return df
|
|
@@ -34,13 +33,32 @@ def get_PC_name():
|
|
|
34
33
|
|
|
35
34
|
def get_PC_abbr_name():
|
|
36
35
|
pc_name = get_PC_name()
|
|
37
|
-
return
|
|
36
|
+
return PC_TO_ABBR.get(pc_name, "Unknown")
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def get_os_platform():
|
|
40
|
+
return platform.system().lower()
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def get_working_disk(abbr_disk_map=ABBR_DISK_MAP):
|
|
44
|
+
pc_abbr = get_PC_abbr_name()
|
|
45
|
+
return abbr_disk_map.get(pc_abbr, None)
|
|
38
46
|
|
|
39
47
|
|
|
40
48
|
# ! This funcction search for full paths in the obj and normalize them according to the current platform and working disk
|
|
41
49
|
# ! E.g: "E:/zdataset/DFire", but working_disk: "D:", current_platform: "windows" => "D:/zdataset/DFire"
|
|
42
50
|
# ! E.g: "E:/zdataset/DFire", but working_disk: "D:", current_platform: "linux" => "/mnt/d/zdataset/DFire"
|
|
43
|
-
def normalize_paths(obj, working_disk, current_platform):
|
|
51
|
+
def normalize_paths(obj, working_disk=None, current_platform=None):
|
|
52
|
+
# [FIX 3] Resolve defaults inside function to be safer/cleaner
|
|
53
|
+
if working_disk is None:
|
|
54
|
+
working_disk = get_working_disk()
|
|
55
|
+
if current_platform is None:
|
|
56
|
+
current_platform = get_os_platform()
|
|
57
|
+
|
|
58
|
+
# [FIX 2] If PC is unknown, working_disk is None. Return early to avoid crash.
|
|
59
|
+
if working_disk is None:
|
|
60
|
+
return obj
|
|
61
|
+
|
|
44
62
|
if isinstance(obj, dict):
|
|
45
63
|
for key, value in obj.items():
|
|
46
64
|
obj[key] = normalize_paths(value, working_disk, current_platform)
|
|
@@ -52,22 +70,25 @@ def normalize_paths(obj, working_disk, current_platform):
|
|
|
52
70
|
elif isinstance(obj, str):
|
|
53
71
|
# Normalize backslashes to forward slashes for consistency
|
|
54
72
|
obj = obj.replace("\\", "/")
|
|
73
|
+
|
|
55
74
|
# Regex for Windows-style path: e.g., "E:/zdataset/DFire"
|
|
56
75
|
win_match = re.match(r"^([A-Z]):/(.*)$", obj)
|
|
57
76
|
# Regex for Linux-style path: e.g., "/mnt/e/zdataset/DFire"
|
|
58
77
|
lin_match = re.match(r"^/mnt/([a-z])/(.*)$", obj)
|
|
78
|
+
|
|
59
79
|
if win_match or lin_match:
|
|
60
80
|
rest = win_match.group(2) if win_match else lin_match.group(2)
|
|
81
|
+
|
|
61
82
|
if current_platform == "windows":
|
|
62
83
|
# working_disk is like "D:", so "D:/" + rest
|
|
63
|
-
new_path = working_disk
|
|
84
|
+
new_path = f"{working_disk}/{rest}"
|
|
64
85
|
elif current_platform == "linux":
|
|
65
86
|
# Extract drive letter from working_disk (e.g., "D:" -> "d")
|
|
66
87
|
drive_letter = working_disk[0].lower()
|
|
67
|
-
new_path = "/mnt/
|
|
88
|
+
new_path = f"/mnt/{drive_letter}/{rest}"
|
|
68
89
|
else:
|
|
69
|
-
# Unknown platform, return original
|
|
70
90
|
return obj
|
|
71
91
|
return new_path
|
|
92
|
+
|
|
72
93
|
# For non-strings or non-path strings, return as is
|
|
73
94
|
return obj
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: halib
|
|
3
|
-
Version: 0.2.
|
|
3
|
+
Version: 0.2.6
|
|
4
4
|
Summary: Small library for common tasks
|
|
5
5
|
Author: Hoang Van Ha
|
|
6
6
|
Author-email: hoangvanhauit@gmail.com
|
|
@@ -53,7 +53,7 @@ Dynamic: summary
|
|
|
53
53
|
|
|
54
54
|
# Helper package for coding and automation
|
|
55
55
|
|
|
56
|
-
**Version 0.2.
|
|
56
|
+
**Version 0.2.6**
|
|
57
57
|
+ reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
|
|
58
58
|
|
|
59
59
|
**Version 0.2.1**
|
|
@@ -44,7 +44,7 @@ halib/filetype/ipynb.py,sha256=pd2LgmPa7ZbF0YlQJbeQZEsl6jHQUSoyVtkCT7WhU5Q,1657
|
|
|
44
44
|
halib/filetype/jsonfile.py,sha256=2HcBqXYjLNvqFok3PHOgH59vlhDCZLZpt7ezvgx1TFM,474
|
|
45
45
|
halib/filetype/textfile.py,sha256=3koEFyVme1SEHdud7TnjArHndoiqfMGfMdYY3NIFegM,397
|
|
46
46
|
halib/filetype/videofile.py,sha256=wDyZp7Dh0ZuNgQUvt8gLTpy3Flx1jDr-QsO4-jzriGE,8104
|
|
47
|
-
halib/filetype/yamlfile.py,sha256=
|
|
47
|
+
halib/filetype/yamlfile.py,sha256=buvj016n3wmEBDfeDX9lbljqDk5R5OlKHuXDKSfIKK0,2411
|
|
48
48
|
halib/online/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
49
49
|
halib/online/gdrive.py,sha256=RmF4y6UPxektkKIctmfT-pKWZsBM9FVUeld6zZmJkp0,7787
|
|
50
50
|
halib/online/gdrive_mkdir.py,sha256=wSJkQMJCDuS1gxQ2lHQHq_IrJ4xR_SEoPSo9n_2WNFU,1474
|
|
@@ -91,7 +91,7 @@ halib/sys/filesys.py,sha256=ERpnELLDKJoTIIKf-AajgkY62nID4qmqmX5TkE95APU,2931
|
|
|
91
91
|
halib/system/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
92
92
|
halib/system/cmd.py,sha256=b2x7JPcNnFjLGheIESVYvqAb-w2UwBM1PAwYxMZ5YjA,228
|
|
93
93
|
halib/system/filesys.py,sha256=102J2fkQhmH1_-HQVy2FQ4NOU8LTjMWV3hToT_APtq8,4401
|
|
94
|
-
halib/system/path.py,sha256=
|
|
94
|
+
halib/system/path.py,sha256=uCXTltd943L_2heU2HLwvXcgYJRd8-ZEzDe435419OQ,3165
|
|
95
95
|
halib/utils/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
96
96
|
halib/utils/dataclass_util.py,sha256=rj2IMLlUzbm2OlF5_B2dRTk9njZOaF7tTjYkOsq8uLY,1416
|
|
97
97
|
halib/utils/dict.py,sha256=wYE6Iw-_CnCWdMg9tpJ2Y2-e2ESkW9FxmdBkZkbUh80,299
|
|
@@ -101,8 +101,8 @@ halib/utils/list.py,sha256=BM-8sRhYyqF7bh4p7TQtV7P_gnFruUCA6DTUOombaZg,337
|
|
|
101
101
|
halib/utils/listop.py,sha256=Vpa8_2fI0wySpB2-8sfTBkyi_A4FhoFVVvFiuvW8N64,339
|
|
102
102
|
halib/utils/tele_noti.py,sha256=-4WXZelCA4W9BroapkRyIdUu9cUVrcJJhegnMs_WpGU,5928
|
|
103
103
|
halib/utils/video.py,sha256=zLoj5EHk4SmP9OnoHjO8mLbzPdtq6gQPzTQisOEDdO8,3261
|
|
104
|
-
halib-0.2.
|
|
105
|
-
halib-0.2.
|
|
106
|
-
halib-0.2.
|
|
107
|
-
halib-0.2.
|
|
108
|
-
halib-0.2.
|
|
104
|
+
halib-0.2.6.dist-info/licenses/LICENSE.txt,sha256=qZssdna4aETiR8znYsShUjidu-U4jUT9Q-EWNlZ9yBQ,1100
|
|
105
|
+
halib-0.2.6.dist-info/METADATA,sha256=vOwV5U8ejV_z6eL1YGbkaY5EnMCDQR54Tab1NJsSbIU,6714
|
|
106
|
+
halib-0.2.6.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
107
|
+
halib-0.2.6.dist-info/top_level.txt,sha256=7AD6PLaQTreE0Fn44mdZsoHBe_Zdd7GUmjsWPyQ7I-k,6
|
|
108
|
+
halib-0.2.6.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|