halib 0.2.30__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.
Files changed (110) hide show
  1. halib/__init__.py +94 -0
  2. halib/common/__init__.py +0 -0
  3. halib/common/common.py +326 -0
  4. halib/common/rich_color.py +285 -0
  5. halib/common.py +151 -0
  6. halib/csvfile.py +48 -0
  7. halib/cuda.py +39 -0
  8. halib/dataset.py +209 -0
  9. halib/exp/__init__.py +0 -0
  10. halib/exp/core/__init__.py +0 -0
  11. halib/exp/core/base_config.py +167 -0
  12. halib/exp/core/base_exp.py +147 -0
  13. halib/exp/core/param_gen.py +170 -0
  14. halib/exp/core/wandb_op.py +117 -0
  15. halib/exp/data/__init__.py +0 -0
  16. halib/exp/data/dataclass_util.py +41 -0
  17. halib/exp/data/dataset.py +208 -0
  18. halib/exp/data/torchloader.py +165 -0
  19. halib/exp/perf/__init__.py +0 -0
  20. halib/exp/perf/flop_calc.py +190 -0
  21. halib/exp/perf/gpu_mon.py +58 -0
  22. halib/exp/perf/perfcalc.py +470 -0
  23. halib/exp/perf/perfmetrics.py +137 -0
  24. halib/exp/perf/perftb.py +778 -0
  25. halib/exp/perf/profiler.py +507 -0
  26. halib/exp/viz/__init__.py +0 -0
  27. halib/exp/viz/plot.py +754 -0
  28. halib/filesys.py +117 -0
  29. halib/filetype/__init__.py +0 -0
  30. halib/filetype/csvfile.py +192 -0
  31. halib/filetype/ipynb.py +61 -0
  32. halib/filetype/jsonfile.py +19 -0
  33. halib/filetype/textfile.py +12 -0
  34. halib/filetype/videofile.py +266 -0
  35. halib/filetype/yamlfile.py +87 -0
  36. halib/gdrive.py +179 -0
  37. halib/gdrive_mkdir.py +41 -0
  38. halib/gdrive_test.py +37 -0
  39. halib/jsonfile.py +22 -0
  40. halib/listop.py +13 -0
  41. halib/online/__init__.py +0 -0
  42. halib/online/gdrive.py +229 -0
  43. halib/online/gdrive_mkdir.py +53 -0
  44. halib/online/gdrive_test.py +50 -0
  45. halib/online/projectmake.py +131 -0
  46. halib/online/tele_noti.py +165 -0
  47. halib/plot.py +301 -0
  48. halib/projectmake.py +115 -0
  49. halib/research/__init__.py +0 -0
  50. halib/research/base_config.py +100 -0
  51. halib/research/base_exp.py +157 -0
  52. halib/research/benchquery.py +131 -0
  53. halib/research/core/__init__.py +0 -0
  54. halib/research/core/base_config.py +144 -0
  55. halib/research/core/base_exp.py +157 -0
  56. halib/research/core/param_gen.py +108 -0
  57. halib/research/core/wandb_op.py +117 -0
  58. halib/research/data/__init__.py +0 -0
  59. halib/research/data/dataclass_util.py +41 -0
  60. halib/research/data/dataset.py +208 -0
  61. halib/research/data/torchloader.py +165 -0
  62. halib/research/dataset.py +208 -0
  63. halib/research/flop_csv.py +34 -0
  64. halib/research/flops.py +156 -0
  65. halib/research/metrics.py +137 -0
  66. halib/research/mics.py +74 -0
  67. halib/research/params_gen.py +108 -0
  68. halib/research/perf/__init__.py +0 -0
  69. halib/research/perf/flop_calc.py +190 -0
  70. halib/research/perf/gpu_mon.py +58 -0
  71. halib/research/perf/perfcalc.py +363 -0
  72. halib/research/perf/perfmetrics.py +137 -0
  73. halib/research/perf/perftb.py +778 -0
  74. halib/research/perf/profiler.py +301 -0
  75. halib/research/perfcalc.py +361 -0
  76. halib/research/perftb.py +780 -0
  77. halib/research/plot.py +758 -0
  78. halib/research/profiler.py +300 -0
  79. halib/research/torchloader.py +162 -0
  80. halib/research/viz/__init__.py +0 -0
  81. halib/research/viz/plot.py +754 -0
  82. halib/research/wandb_op.py +116 -0
  83. halib/rich_color.py +285 -0
  84. halib/sys/__init__.py +0 -0
  85. halib/sys/cmd.py +8 -0
  86. halib/sys/filesys.py +124 -0
  87. halib/system/__init__.py +0 -0
  88. halib/system/_list_pc.csv +6 -0
  89. halib/system/cmd.py +8 -0
  90. halib/system/filesys.py +164 -0
  91. halib/system/path.py +106 -0
  92. halib/tele_noti.py +166 -0
  93. halib/textfile.py +13 -0
  94. halib/torchloader.py +162 -0
  95. halib/utils/__init__.py +0 -0
  96. halib/utils/dataclass_util.py +40 -0
  97. halib/utils/dict.py +317 -0
  98. halib/utils/dict_op.py +9 -0
  99. halib/utils/gpu_mon.py +58 -0
  100. halib/utils/list.py +17 -0
  101. halib/utils/listop.py +13 -0
  102. halib/utils/slack.py +86 -0
  103. halib/utils/tele_noti.py +166 -0
  104. halib/utils/video.py +82 -0
  105. halib/videofile.py +139 -0
  106. halib-0.2.30.dist-info/METADATA +237 -0
  107. halib-0.2.30.dist-info/RECORD +110 -0
  108. halib-0.2.30.dist-info/WHEEL +5 -0
  109. halib-0.2.30.dist-info/licenses/LICENSE.txt +17 -0
  110. halib-0.2.30.dist-info/top_level.txt +1 -0
halib/__init__.py ADDED
@@ -0,0 +1,94 @@
1
+ __all__ = [
2
+ "arrow",
3
+ "cmd",
4
+ "console_log",
5
+ "console",
6
+ "ConsoleLog",
7
+ "csvfile",
8
+ "DictConfig",
9
+ "filetype",
10
+ "fs",
11
+ "inspect",
12
+ "load_yaml",
13
+ "log_func",
14
+ "logger",
15
+ "norm_str",
16
+ "now_str",
17
+ "np",
18
+ "omegaconf",
19
+ "OmegaConf",
20
+ "os",
21
+ "pad_string",
22
+ "pd",
23
+ "plt",
24
+ "pprint_box",
25
+ "pprint_local_path",
26
+ "pprint_stack_trace",
27
+ "pprint",
28
+ "px",
29
+ "rcolor_all_str",
30
+ "rcolor_palette_all",
31
+ "rcolor_palette",
32
+ "rcolor_str",
33
+ "re",
34
+ "rprint",
35
+ "sns",
36
+ "tcuda",
37
+ "time",
38
+ "timebudget",
39
+ "tqdm",
40
+ "warnings",
41
+ ]
42
+ import warnings
43
+
44
+ warnings.filterwarnings("ignore", message="Unable to import Axes3D")
45
+
46
+ # common libraries
47
+ import re
48
+ from tqdm import tqdm
49
+ import arrow
50
+ import numpy as np
51
+ import pandas as pd
52
+ import os
53
+ import time
54
+
55
+ # my own modules
56
+ from .filetype import *
57
+ from .filetype.yamlfile import load_yaml
58
+ from .system import cmd
59
+ from .system import filesys as fs
60
+ from .filetype import csvfile
61
+ from .common.common import (
62
+ console,
63
+ console_log,
64
+ ConsoleLog,
65
+ now_str,
66
+ norm_str,
67
+ pprint_box,
68
+ pprint_local_path,
69
+ pprint_stack_trace,
70
+ tcuda,
71
+ log_func,
72
+ pad_string,
73
+ )
74
+
75
+ # for log
76
+ from loguru import logger
77
+ from rich import inspect
78
+ from rich import print as rprint
79
+ from rich.pretty import pprint
80
+ from timebudget import timebudget
81
+ import omegaconf
82
+ from omegaconf import OmegaConf
83
+ from omegaconf.dictconfig import DictConfig
84
+ from .common.rich_color import (
85
+ rcolor_str,
86
+ rcolor_palette,
87
+ rcolor_palette_all,
88
+ rcolor_all_str,
89
+ )
90
+
91
+ # for visualization
92
+ import seaborn as sns
93
+ import matplotlib.pyplot as plt
94
+ import plotly.express as px
File without changes
halib/common/common.py ADDED
@@ -0,0 +1,326 @@
1
+ import os
2
+ import sys
3
+ import re
4
+ import arrow
5
+ import importlib
6
+
7
+ import rich
8
+ from rich import print
9
+ from rich.panel import Panel
10
+ from rich.console import Console
11
+ from rich.pretty import pprint, Pretty
12
+
13
+ from pathlib import Path, PureWindowsPath
14
+ from typing import Optional
15
+ from loguru import logger
16
+
17
+ import functools
18
+ from typing import Callable, List, Literal, Union
19
+ import time
20
+ import math
21
+
22
+ console = Console()
23
+
24
+
25
+ def seed_everything(seed=42):
26
+ import random
27
+ import numpy as np
28
+
29
+ random.seed(seed)
30
+ np.random.seed(seed)
31
+ # import torch if it is available
32
+ try:
33
+ import torch
34
+
35
+ torch.manual_seed(seed)
36
+ torch.cuda.manual_seed(seed)
37
+ torch.cuda.manual_seed_all(seed)
38
+ torch.backends.cudnn.deterministic = True
39
+ torch.backends.cudnn.benchmark = False
40
+ except ImportError:
41
+ pprint("torch not imported, skipping torch seed_everything")
42
+ pass
43
+
44
+
45
+ def now_str(sep_date_time="."):
46
+ assert sep_date_time in [
47
+ ".",
48
+ "_",
49
+ "-",
50
+ ], "sep_date_time must be one of '.', '_', or '-'"
51
+ now_string = arrow.now().format(f"YYYYMMDD{sep_date_time}HHmmss")
52
+ return now_string
53
+
54
+
55
+ def pad_string(
56
+ text: str,
57
+ target_width: Union[int, float] = -1,
58
+ pad_char: str = ".",
59
+ pad_sides: List[Literal["left", "right"]] = ["left", "right"], # type: ignore
60
+ ) -> str:
61
+ """
62
+ Pads a string to a specific width or a relative multiplier width.
63
+
64
+ Args:
65
+ text: The input string.
66
+ target_width:
67
+ - If int (e.g., 20): The exact total length of the resulting string.
68
+ - If float (e.g., 1.5): Multiplies original length (must be >= 1.0).
69
+ (e.g., length 10 * 1.5 = target width 15).
70
+ pad_char: The character to use for padding.
71
+ pad_sides: A list containing "left", "right", or both.
72
+ """
73
+ current_len = len(text)
74
+
75
+ # 1. Calculate the final integer target width
76
+ if isinstance(target_width, float):
77
+ if target_width < 1.0:
78
+ raise ValueError(f"Float target_width must be >= 1.0, got {target_width}")
79
+ # Use math.ceil to ensure we don't under-pad (e.g. 1.5 * 5 = 7.5 -> 8)
80
+ final_width = math.ceil(current_len * target_width)
81
+ else:
82
+ final_width = target_width
83
+
84
+ # 2. Return early if no padding needed
85
+ if current_len >= final_width:
86
+ return text
87
+
88
+ # 3. Calculate total padding needed
89
+ padding_needed = final_width - current_len
90
+
91
+ # CASE 1: Pad Both Sides (Center)
92
+ if "left" in pad_sides and "right" in pad_sides:
93
+ left_pad_count = padding_needed // 2
94
+ right_pad_count = padding_needed - left_pad_count
95
+ return (pad_char * left_pad_count) + text + (pad_char * right_pad_count)
96
+
97
+ # CASE 2: Pad Left Only (Right Align)
98
+ elif "left" in pad_sides:
99
+ return (pad_char * padding_needed) + text
100
+
101
+ # CASE 3: Pad Right Only (Left Align)
102
+ elif "right" in pad_sides:
103
+ return text + (pad_char * padding_needed)
104
+
105
+ return text
106
+
107
+
108
+ # ==========================================
109
+ # Usage Examples
110
+ # ==========================================
111
+ if __name__ == "__main__":
112
+ s = "Hello"
113
+
114
+ # 1. Default (Both sides / Center)
115
+ print(f"'{pad_string(s, 11)}'")
116
+ # Output: "'***Hello***'"
117
+
118
+ # 2. Left Only
119
+ print(f"'{pad_string(s, 10, '-', ['left'])}'")
120
+ # Output: "'-----Hello'"
121
+
122
+ # 3. Right Only
123
+ print(f"'{pad_string(s, 10, '.', ['right'])}'")
124
+ # Output: "'Hello.....'"
125
+
126
+
127
+ def norm_str(in_str):
128
+ # Replace one or more whitespace characters with a single underscore
129
+ norm_string = re.sub(r"\s+", "_", in_str)
130
+ # Remove leading and trailing spaces
131
+ norm_string = norm_string.strip()
132
+ return norm_string
133
+
134
+
135
+ def pprint_box(obj, title="", border_style="green"):
136
+ """
137
+ Pretty print an object in a box.
138
+ """
139
+ rich.print(
140
+ Panel(Pretty(obj, expand_all=True), title=title, border_style=border_style)
141
+ )
142
+
143
+
144
+ def console_rule(msg, do_norm_msg=True, is_end_tag=False):
145
+ msg = norm_str(msg) if do_norm_msg else msg
146
+ if is_end_tag:
147
+ console.rule(f"</{msg}>")
148
+ else:
149
+ console.rule(f"<{msg}>")
150
+
151
+
152
+ def console_log(func):
153
+ def wrapper(*args, **kwargs):
154
+ console_rule(func.__name__)
155
+ result = func(*args, **kwargs)
156
+ console_rule(func.__name__, is_end_tag=True)
157
+ return result
158
+
159
+ return wrapper
160
+
161
+
162
+ class ConsoleLog:
163
+ def __init__(self, message):
164
+ self.message = message
165
+
166
+ def __enter__(self):
167
+ console_rule(self.message)
168
+ return self
169
+
170
+ def __exit__(self, exc_type, exc_value, traceback):
171
+ console_rule(self.message, is_end_tag=True)
172
+ if exc_type is not None:
173
+ print(f"An exception of type {exc_type} occurred.")
174
+ print(f"Exception message: {exc_value}")
175
+
176
+
177
+ def linux_to_wins_path(path: str) -> str:
178
+ """
179
+ Convert a Linux-style WSL path (/mnt/c/... or /mnt/d/...) to a Windows-style path (C:\...).
180
+ """
181
+ # Handle only /mnt/<drive>/... style
182
+ if (
183
+ path.startswith("/mnt/")
184
+ and len(path) > 6
185
+ and path[5].isalpha()
186
+ and path[6] == "/"
187
+ ):
188
+ drive = path[5].upper() # Extract drive letter
189
+ win_path = f"{drive}:{path[6:]}" # Replace "/mnt/c/" with "C:/"
190
+ else:
191
+ win_path = path # Return unchanged if not a WSL-style path
192
+ # Normalize to Windows-style backslashes
193
+ return str(PureWindowsPath(win_path))
194
+
195
+
196
+ DEFAULT_STACK_TRACE_MSG = "Caused by halib.common.common.pprint_stack_trace"
197
+
198
+
199
+ def pprint_stack_trace(
200
+ msg: str = DEFAULT_STACK_TRACE_MSG,
201
+ e: Optional[Exception] = None,
202
+ force_stop: bool = False,
203
+ ):
204
+ """
205
+ Print the current stack trace or the stack trace of an exception.
206
+ """
207
+ try:
208
+ if e is not None:
209
+ raise e
210
+ else:
211
+ raise Exception("pprint_stack_trace called")
212
+ except Exception as e:
213
+ # attach the exception trace to a warning
214
+ global DEFAULT_STACK_TRACE_MSG
215
+ if len(msg.strip()) == 0:
216
+ msg = DEFAULT_STACK_TRACE_MSG
217
+ logger.opt(exception=e).warning(msg)
218
+ if force_stop:
219
+ console.rule(
220
+ "[red]Force Stop Triggered in <halib.common.pprint_stack_trace>[/red]"
221
+ )
222
+ sys.exit(1)
223
+
224
+
225
+ def pprint_local_path(
226
+ local_path: str, get_wins_path: bool = False, tag: str = ""
227
+ ) -> str:
228
+ """
229
+ Pretty-print a local path with emoji and clickable file:// URI.
230
+
231
+ Args:
232
+ local_path: Path to file or directory (Linux or Windows style).
233
+ get_wins_path: If True on Linux, convert WSL-style path to Windows style before printing.
234
+ tag: Optional console log tag.
235
+
236
+ Returns:
237
+ The file URI string.
238
+ """
239
+ p = Path(local_path).resolve()
240
+ type_str = "📄" if p.is_file() else "📁" if p.is_dir() else "❓"
241
+
242
+ if get_wins_path and os.name == "posix":
243
+ # Try WSL → Windows conversion
244
+ converted = linux_to_wins_path(str(p))
245
+ if converted != str(p): # Conversion happened
246
+ file_uri = str(PureWindowsPath(converted).as_uri())
247
+ else:
248
+ file_uri = p.as_uri()
249
+ else:
250
+ file_uri = p.as_uri()
251
+
252
+ content_str = f"{type_str} [link={file_uri}]{file_uri}[/link]"
253
+
254
+ if tag:
255
+ with ConsoleLog(tag):
256
+ console.print(content_str)
257
+ else:
258
+ console.print(content_str)
259
+
260
+ return file_uri
261
+
262
+
263
+ def log_func(
264
+ func: Optional[Callable] = None, *, log_time: bool = False, log_args: bool = False
265
+ ):
266
+ """
267
+ A decorator that logs the start/end of a function.
268
+ Supports both @log_func and @log_func(log_time=True) usage.
269
+ """
270
+ # 1. HANDLE ARGUMENTS: If called as @log_func(log_time=True), func is None.
271
+ # We return a 'partial' function that remembers the args and waits for the func.
272
+ if func is None:
273
+ return functools.partial(log_func, log_time=log_time, log_args=log_args)
274
+
275
+ # 2. HANDLE DECORATION: If called as @log_func, func is the actual function.
276
+ @functools.wraps(func)
277
+ def wrapper(*args, **kwargs):
278
+ # Safe way to get name (handles partials/lambdas)
279
+ func_name = getattr(func, "__name__", "Unknown_Func")
280
+
281
+ # Note: Ensure 'ConsoleLog' context manager is available in your scope
282
+ with ConsoleLog(func_name):
283
+ start = time.perf_counter()
284
+ try:
285
+ result = func(*args, **kwargs)
286
+ finally:
287
+ # We use finally to ensure logging happens even if func crashes
288
+ end = time.perf_counter()
289
+
290
+ if log_time or log_args:
291
+
292
+ console.print(pad_string(f"Func <{func_name}> summary", 80))
293
+ if log_time:
294
+ console.print(f"{func_name} took {end - start:.6f} seconds")
295
+ if log_args:
296
+ console.print(f"Args: {args}, Kwargs: {kwargs}")
297
+
298
+ return result
299
+
300
+ return wrapper
301
+
302
+
303
+ def tcuda():
304
+ NOT_INSTALLED = "Not Installed"
305
+ GPU_AVAILABLE = "GPU(s) Available"
306
+ ls_lib = ["torch", "tensorflow"]
307
+ lib_stats = {lib: NOT_INSTALLED for lib in ls_lib}
308
+ for lib in ls_lib:
309
+ spec = importlib.util.find_spec(lib) # ty:ignore[possibly-missing-attribute]
310
+ if spec:
311
+ if lib == "torch":
312
+ import torch
313
+
314
+ lib_stats[lib] = str(torch.cuda.device_count()) + " " + GPU_AVAILABLE
315
+ elif lib == "tensorflow":
316
+ import tensorflow as tf # type: ignore
317
+
318
+ lib_stats[lib] = (
319
+ str(len(tf.config.list_physical_devices("GPU")))
320
+ + " "
321
+ + GPU_AVAILABLE
322
+ )
323
+ console.rule("<CUDA Library Stats>")
324
+ pprint(lib_stats)
325
+ console.rule("</CUDA Library Stats>")
326
+ return lib_stats
@@ -0,0 +1,285 @@
1
+ from rich.console import Console
2
+ from rich.pretty import pprint
3
+ from rich.table import Table
4
+ from rich.text import Text
5
+ from rich.panel import Panel
6
+
7
+ # List of colors
8
+ # ! https://rich.readthedocs.io/en/stable/appendix/colors.html
9
+ all_colors = [
10
+ "black",
11
+ "red",
12
+ "green",
13
+ "yellow",
14
+ "blue",
15
+ "magenta",
16
+ "cyan",
17
+ "white",
18
+ "bright_black",
19
+ "bright_red",
20
+ "bright_green",
21
+ "bright_yellow",
22
+ "bright_blue",
23
+ "bright_magenta",
24
+ "bright_cyan",
25
+ "bright_white",
26
+ "grey0",
27
+ "navy_blue",
28
+ "dark_blue",
29
+ "blue3",
30
+ "blue1",
31
+ "dark_green",
32
+ "deep_sky_blue4",
33
+ "dodger_blue3",
34
+ "dodger_blue2",
35
+ "green4",
36
+ "spring_green4",
37
+ "turquoise4",
38
+ "deep_sky_blue3",
39
+ "dodger_blue1",
40
+ "dark_cyan",
41
+ "light_sea_green",
42
+ "deep_sky_blue2",
43
+ "deep_sky_blue1",
44
+ "green3",
45
+ "spring_green3",
46
+ "cyan3",
47
+ "dark_turquoise",
48
+ "turquoise2",
49
+ "green1",
50
+ "spring_green2",
51
+ "spring_green1",
52
+ "medium_spring_green",
53
+ "cyan2",
54
+ "cyan1",
55
+ "purple4",
56
+ "purple3",
57
+ "blue_violet",
58
+ "grey37",
59
+ "medium_purple4",
60
+ "slate_blue3",
61
+ "royal_blue1",
62
+ "chartreuse4",
63
+ "pale_turquoise4",
64
+ "steel_blue",
65
+ "steel_blue3",
66
+ "cornflower_blue",
67
+ "dark_sea_green4",
68
+ "cadet_blue",
69
+ "sky_blue3",
70
+ "chartreuse3",
71
+ "sea_green3",
72
+ "aquamarine3",
73
+ "medium_turquoise",
74
+ "steel_blue1",
75
+ "sea_green2",
76
+ "sea_green1",
77
+ "dark_slate_gray2",
78
+ "dark_red",
79
+ "dark_magenta",
80
+ "orange4",
81
+ "light_pink4",
82
+ "plum4",
83
+ "medium_purple3",
84
+ "slate_blue1",
85
+ "wheat4",
86
+ "grey53",
87
+ "light_slate_grey",
88
+ "medium_purple",
89
+ "light_slate_blue",
90
+ "yellow4",
91
+ "dark_sea_green",
92
+ "light_sky_blue3",
93
+ "sky_blue2",
94
+ "chartreuse2",
95
+ "pale_green3",
96
+ "dark_slate_gray3",
97
+ "sky_blue1",
98
+ "chartreuse1",
99
+ "light_green",
100
+ "aquamarine1",
101
+ "dark_slate_gray1",
102
+ "deep_pink4",
103
+ "medium_violet_red",
104
+ "dark_violet",
105
+ "purple",
106
+ "medium_orchid3",
107
+ "medium_orchid",
108
+ "dark_goldenrod",
109
+ "rosy_brown",
110
+ "grey63",
111
+ "medium_purple2",
112
+ "medium_purple1",
113
+ "dark_khaki",
114
+ "navajo_white3",
115
+ "grey69",
116
+ "light_steel_blue3",
117
+ "light_steel_blue",
118
+ "dark_olive_green3",
119
+ "dark_sea_green3",
120
+ "light_cyan3",
121
+ "light_sky_blue1",
122
+ "green_yellow",
123
+ "dark_olive_green2",
124
+ "pale_green1",
125
+ "dark_sea_green2",
126
+ "pale_turquoise1",
127
+ "red3",
128
+ "deep_pink3",
129
+ "magenta3",
130
+ "dark_orange3",
131
+ "indian_red",
132
+ "hot_pink3",
133
+ "hot_pink2",
134
+ "orchid",
135
+ "orange3",
136
+ "light_salmon3",
137
+ "light_pink3",
138
+ "pink3",
139
+ "plum3",
140
+ "violet",
141
+ "gold3",
142
+ "light_goldenrod3",
143
+ "tan",
144
+ "misty_rose3",
145
+ "thistle3",
146
+ "plum2",
147
+ "yellow3",
148
+ "khaki3",
149
+ "light_yellow3",
150
+ "grey84",
151
+ "light_steel_blue1",
152
+ "yellow2",
153
+ "dark_olive_green1",
154
+ "dark_sea_green1",
155
+ "honeydew2",
156
+ "light_cyan1",
157
+ "red1",
158
+ "deep_pink2",
159
+ "deep_pink1",
160
+ "magenta2",
161
+ "magenta1",
162
+ "orange_red1",
163
+ "indian_red1",
164
+ "hot_pink",
165
+ "medium_orchid1",
166
+ "dark_orange",
167
+ "salmon1",
168
+ "light_coral",
169
+ "pale_violet_red1",
170
+ "orchid2",
171
+ "orchid1",
172
+ "orange1",
173
+ "sandy_brown",
174
+ "light_salmon1",
175
+ "light_pink1",
176
+ "pink1",
177
+ "plum1",
178
+ "gold1",
179
+ "light_goldenrod2",
180
+ "navajo_white1",
181
+ "misty_rose1",
182
+ "thistle1",
183
+ "yellow1",
184
+ "light_goldenrod1",
185
+ "khaki1",
186
+ "wheat1",
187
+ "cornsilk1",
188
+ "grey100",
189
+ "grey3",
190
+ "grey7",
191
+ "grey11",
192
+ "grey15",
193
+ "grey19",
194
+ "grey23",
195
+ "grey27",
196
+ "grey30",
197
+ "grey35",
198
+ "grey39",
199
+ "grey42",
200
+ "grey46",
201
+ "grey50",
202
+ "grey54",
203
+ "grey58",
204
+ "grey62",
205
+ "grey66",
206
+ "grey70",
207
+ "grey74",
208
+ "grey78",
209
+ "grey82",
210
+ "grey85",
211
+ "grey89",
212
+ "grey93",
213
+ ]
214
+
215
+ basic_colors = [
216
+ "black",
217
+ "red",
218
+ "green",
219
+ "yellow",
220
+ "blue",
221
+ "magenta",
222
+ "cyan",
223
+ "white",
224
+ "bright_black",
225
+ "bright_red",
226
+ "bright_green",
227
+ "bright_yellow",
228
+ "bright_blue",
229
+ "bright_magenta",
230
+ "bright_cyan",
231
+ "bright_white",
232
+ ]
233
+
234
+ def rcolor_all_str():
235
+ pprint(all_colors)
236
+
237
+ def rcolor_basic_str():
238
+ pprint(basic_colors)
239
+
240
+ def rcolor_str(in_str, color="white"):
241
+ assert color in all_colors, f"color must be one of {all_colors}"
242
+ return f"[{color}]{in_str}[/{color}]"
243
+
244
+ def rcolor_palette(color_list):
245
+ # make sure all colors are valid (in all_colors)
246
+ for color in color_list:
247
+ assert (
248
+ color in all_colors
249
+ ), f"color must be a valid color. call <rcolor_all_str()> or <rcolor_palette_all()> to see all valid colors"
250
+ # Initialize console
251
+ console = Console()
252
+
253
+ # Create a table with horizontal lines and six columns
254
+ table = Table(show_header=True, header_style="bold magenta", show_lines=True)
255
+
256
+ # Define the columns
257
+ table.add_column("Color Name 1", style="bold")
258
+ table.add_column("Sample 1", style="bold")
259
+ table.add_column("Color Name 2", style="bold")
260
+ table.add_column("Sample 2", style="bold")
261
+ table.add_column("Color Name 3", style="bold")
262
+ table.add_column("Sample 3", style="bold")
263
+
264
+ # Adjust the number of rows needed for the table
265
+ num_colors = len(color_list)
266
+ num_rows = (num_colors + 2) // 3 # Ceiling division to ensure all colors fit
267
+
268
+ # Add rows to the table
269
+ for i in range(num_rows):
270
+ color1 = color_list[i * 3] if i * 3 < num_colors else ""
271
+ color2 = color_list[i * 3 + 1] if i * 3 + 1 < num_colors else ""
272
+ color3 = color_list[i * 3 + 2] if i * 3 + 2 < num_colors else ""
273
+ filled_rect1 = Text(" " * 10, style=f"on {color1}") if color1 else ""
274
+ filled_rect2 = Text(" " * 10, style=f"on {color2}") if color2 else ""
275
+ filled_rect3 = Text(" " * 10, style=f"on {color3}") if color3 else ""
276
+ table.add_row(color1, filled_rect1, color2, filled_rect2, color3, filled_rect3)
277
+
278
+ # Print the table
279
+ console.print(table)
280
+
281
+ def rcolor_palette_basic():
282
+ rcolor_palette(basic_colors)
283
+
284
+ def rcolor_palette_all():
285
+ rcolor_palette(all_colors)