halib 0.2.14__tar.gz → 0.2.16__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 (56) hide show
  1. {halib-0.2.14 → halib-0.2.16}/PKG-INFO +4 -3
  2. {halib-0.2.14 → halib-0.2.16}/README.md +2 -2
  3. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/profiler.py +45 -1
  4. {halib-0.2.14 → halib-0.2.16}/halib/filetype/videofile.py +28 -1
  5. {halib-0.2.14 → halib-0.2.16}/halib.egg-info/PKG-INFO +4 -3
  6. {halib-0.2.14 → halib-0.2.16}/halib.egg-info/requires.txt +1 -0
  7. {halib-0.2.14 → halib-0.2.16}/setup.py +1 -1
  8. {halib-0.2.14 → halib-0.2.16}/.gitignore +0 -0
  9. {halib-0.2.14 → halib-0.2.16}/GDriveFolder.txt +0 -0
  10. {halib-0.2.14 → halib-0.2.16}/LICENSE.txt +0 -0
  11. {halib-0.2.14 → halib-0.2.16}/MANIFEST.in +0 -0
  12. {halib-0.2.14 → halib-0.2.16}/halib/__init__.py +0 -0
  13. {halib-0.2.14 → halib-0.2.16}/halib/common/__init__.py +0 -0
  14. {halib-0.2.14 → halib-0.2.16}/halib/common/common.py +0 -0
  15. {halib-0.2.14 → halib-0.2.16}/halib/common/rich_color.py +0 -0
  16. {halib-0.2.14 → halib-0.2.16}/halib/exp/__init__.py +0 -0
  17. {halib-0.2.14 → halib-0.2.16}/halib/exp/core/__init__.py +0 -0
  18. {halib-0.2.14 → halib-0.2.16}/halib/exp/core/base_config.py +0 -0
  19. {halib-0.2.14 → halib-0.2.16}/halib/exp/core/base_exp.py +0 -0
  20. {halib-0.2.14 → halib-0.2.16}/halib/exp/core/param_gen.py +0 -0
  21. {halib-0.2.14 → halib-0.2.16}/halib/exp/core/wandb_op.py +0 -0
  22. {halib-0.2.14 → halib-0.2.16}/halib/exp/data/__init__.py +0 -0
  23. {halib-0.2.14 → halib-0.2.16}/halib/exp/data/dataclass_util.py +0 -0
  24. {halib-0.2.14 → halib-0.2.16}/halib/exp/data/dataset.py +0 -0
  25. {halib-0.2.14 → halib-0.2.16}/halib/exp/data/torchloader.py +0 -0
  26. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/__init__.py +0 -0
  27. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/flop_calc.py +0 -0
  28. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/gpu_mon.py +0 -0
  29. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/perfcalc.py +0 -0
  30. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/perfmetrics.py +0 -0
  31. {halib-0.2.14 → halib-0.2.16}/halib/exp/perf/perftb.py +0 -0
  32. {halib-0.2.14 → halib-0.2.16}/halib/exp/viz/__init__.py +0 -0
  33. {halib-0.2.14 → halib-0.2.16}/halib/exp/viz/plot.py +0 -0
  34. {halib-0.2.14 → halib-0.2.16}/halib/filetype/__init__.py +0 -0
  35. {halib-0.2.14 → halib-0.2.16}/halib/filetype/csvfile.py +0 -0
  36. {halib-0.2.14 → halib-0.2.16}/halib/filetype/ipynb.py +0 -0
  37. {halib-0.2.14 → halib-0.2.16}/halib/filetype/jsonfile.py +0 -0
  38. {halib-0.2.14 → halib-0.2.16}/halib/filetype/textfile.py +0 -0
  39. {halib-0.2.14 → halib-0.2.16}/halib/filetype/yamlfile.py +0 -0
  40. {halib-0.2.14 → halib-0.2.16}/halib/online/__init__.py +0 -0
  41. {halib-0.2.14 → halib-0.2.16}/halib/online/gdrive.py +0 -0
  42. {halib-0.2.14 → halib-0.2.16}/halib/online/gdrive_mkdir.py +0 -0
  43. {halib-0.2.14 → halib-0.2.16}/halib/online/projectmake.py +0 -0
  44. {halib-0.2.14 → halib-0.2.16}/halib/online/tele_noti.py +0 -0
  45. {halib-0.2.14 → halib-0.2.16}/halib/system/__init__.py +0 -0
  46. {halib-0.2.14 → halib-0.2.16}/halib/system/_list_pc.csv +0 -0
  47. {halib-0.2.14 → halib-0.2.16}/halib/system/cmd.py +0 -0
  48. {halib-0.2.14 → halib-0.2.16}/halib/system/filesys.py +0 -0
  49. {halib-0.2.14 → halib-0.2.16}/halib/system/path.py +0 -0
  50. {halib-0.2.14 → halib-0.2.16}/halib/utils/__init__.py +0 -0
  51. {halib-0.2.14 → halib-0.2.16}/halib/utils/dict.py +0 -0
  52. {halib-0.2.14 → halib-0.2.16}/halib/utils/list.py +0 -0
  53. {halib-0.2.14 → halib-0.2.16}/halib.egg-info/SOURCES.txt +0 -0
  54. {halib-0.2.14 → halib-0.2.16}/halib.egg-info/dependency_links.txt +0 -0
  55. {halib-0.2.14 → halib-0.2.16}/halib.egg-info/top_level.txt +0 -0
  56. {halib-0.2.14 → halib-0.2.16}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.14
3
+ Version: 0.2.16
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -41,6 +41,7 @@ Requires-Dist: tqdm
41
41
  Requires-Dist: tube_dl
42
42
  Requires-Dist: wandb
43
43
  Requires-Dist: ipynbname
44
+ Requires-Dist: typed-argument-parser
44
45
  Dynamic: author
45
46
  Dynamic: author-email
46
47
  Dynamic: classifier
@@ -53,8 +54,8 @@ Dynamic: summary
53
54
 
54
55
  # Helper package for coding and automation
55
56
 
56
- **Version 0.2.14**
57
- + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
57
+ **Version 0.2.16**
58
+ + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically, also add `measure` context manager to simplify measuring code blocks.
58
59
 
59
60
  **Version 0.2.13**
60
61
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
@@ -1,7 +1,7 @@
1
1
  # Helper package for coding and automation
2
2
 
3
- **Version 0.2.14**
4
- + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
3
+ **Version 0.2.16**
4
+ + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically, also add `measure` context manager to simplify measuring code blocks.
5
5
 
6
6
  **Version 0.2.13**
7
7
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
@@ -12,6 +12,8 @@ from plotly.subplots import make_subplots
12
12
  import plotly.graph_objects as go
13
13
  import plotly.express as px # for dynamic color scales
14
14
 
15
+ from contextlib import contextmanager
16
+
15
17
  from ...common.common import ConsoleLog
16
18
  from ...system.path import *
17
19
 
@@ -43,6 +45,20 @@ def check_enabled(func):
43
45
  # ==========================================
44
46
  # 2. The Class
45
47
  # ==========================================
48
+ class ContextScope:
49
+ """Helper to remember the current context name so you don't have to repeat it."""
50
+
51
+ def __init__(self, profiler, ctx_name):
52
+ self.profiler = profiler
53
+ self.ctx_name = ctx_name
54
+
55
+ @contextmanager
56
+ def step(self, step_name):
57
+ # Automatically passes the stored ctx_name + the new step_name
58
+ with self.profiler.measure(self.ctx_name, step_name):
59
+ yield
60
+
61
+
46
62
  class zProfiler:
47
63
  """A singleton profiler to measure execution time of contexts and steps.
48
64
 
@@ -52,13 +68,23 @@ class zProfiler:
52
68
  output_file (str): Path to save the profiling report.
53
69
  report_format (str): Output format for reports ("json" or "csv").
54
70
 
55
- Example:
71
+ Example (using context manager):
72
+ prof = zProfiler()
73
+ with prof.measure("my_context") as ctx:
74
+ with ctx.step("step1"):
75
+ time.sleep(0.1)
76
+ with ctx.step("step2"):
77
+ time.sleep(0.2)
78
+
79
+ Example (using raw methods):
56
80
  prof = zProfiler()
57
81
  prof.ctx_start("my_context")
58
82
  prof.step_start("my_context", "step1")
59
83
  time.sleep(0.1)
60
84
  prof.step_end("my_context", "step1")
61
85
  prof.ctx_end("my_context")
86
+
87
+
62
88
  """
63
89
 
64
90
  _instance = None
@@ -127,6 +153,24 @@ class zProfiler:
127
153
  return
128
154
  self.time_dict[ctx_name]["step_dict"][step_name][-1].append(time.perf_counter())
129
155
 
156
+ @contextmanager
157
+ def measure(self, ctx_name, step_name=None):
158
+ if step_name is None:
159
+ # --- Context Mode ---
160
+ self.ctx_start(ctx_name)
161
+ try:
162
+ # Yield the helper object initialized with the current context name
163
+ yield ContextScope(self, ctx_name)
164
+ finally:
165
+ self.ctx_end(ctx_name)
166
+ else:
167
+ # --- Step Mode ---
168
+ self.step_start(ctx_name, step_name)
169
+ try:
170
+ yield
171
+ finally:
172
+ self.step_end(ctx_name, step_name)
173
+
130
174
  def _step_dict_to_detail(self, ctx_step_dict):
131
175
  """
132
176
  'ctx_step_dict': {
@@ -96,6 +96,34 @@ class VideoUtils:
96
96
  return dfmk["video_meta"].copy()
97
97
 
98
98
 
99
+ # -----------------------------
100
+ # FFmpeg Horizontal Stack
101
+ # -----------------------------
102
+ @staticmethod
103
+ def video_hstack(video_files, output_file):
104
+ """Horizontally stack multiple videos using FFmpeg."""
105
+ tmp_file = "video_list.txt"
106
+ try:
107
+ with open(tmp_file, "w") as f:
108
+ for video in video_files:
109
+ f.write(f"file '{video}'\n")
110
+
111
+ ffmpeg_cmd = (
112
+ f"ffmpeg -f concat -safe 0 -i {tmp_file} "
113
+ f'-filter_complex "[0:v][1:v][2:v]hstack=inputs={len(video_files)}[v]" '
114
+ f'-map "[v]" -c:v libx264 -preset fast -crf 22 {output_file}'
115
+ )
116
+
117
+ os.system(ffmpeg_cmd)
118
+ print(f"[INFO] Video stacked successfully: {output_file}")
119
+
120
+ except Exception as e:
121
+ print(f"[ERROR] Video stacking failed: {e}")
122
+ finally:
123
+ if os.path.exists(tmp_file):
124
+ os.remove(tmp_file)
125
+
126
+
99
127
  class VideoResolution(Enum):
100
128
  VR480p = "720x480"
101
129
  VR576p = "1280x720"
@@ -146,7 +174,6 @@ def trim_video(source, destination, start_time, end_time):
146
174
 
147
175
  progress_bar = None
148
176
 
149
-
150
177
  def on_progress(bytes_done, total_bytes):
151
178
  global progress_bar
152
179
  if progress_bar is None:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: halib
3
- Version: 0.2.14
3
+ Version: 0.2.16
4
4
  Summary: Small library for common tasks
5
5
  Author: Hoang Van Ha
6
6
  Author-email: hoangvanhauit@gmail.com
@@ -41,6 +41,7 @@ Requires-Dist: tqdm
41
41
  Requires-Dist: tube_dl
42
42
  Requires-Dist: wandb
43
43
  Requires-Dist: ipynbname
44
+ Requires-Dist: typed-argument-parser
44
45
  Dynamic: author
45
46
  Dynamic: author-email
46
47
  Dynamic: classifier
@@ -53,8 +54,8 @@ Dynamic: summary
53
54
 
54
55
  # Helper package for coding and automation
55
56
 
56
- **Version 0.2.14**
57
- + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically
57
+ **Version 0.2.16**
58
+ + update `exp.perf.profiler`: add `enabled` flag to enable/disable profiling dynamically, also add `measure` context manager to simplify measuring code blocks.
58
59
 
59
60
  **Version 0.2.13**
60
61
  + reorganize packages with most changes in `research` package; also rename `research` to `exp` (package for experiment management and utilities)
@@ -29,3 +29,4 @@ tqdm
29
29
  tube_dl
30
30
  wandb
31
31
  ipynbname
32
+ typed-argument-parser
@@ -8,7 +8,7 @@ with open("requirements.txt") as f:
8
8
 
9
9
  setuptools.setup(
10
10
  name="halib",
11
- version="0.2.14",
11
+ version="0.2.16",
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
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