byzh-core 0.0.4.0__tar.gz → 0.0.6.0__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 (36) hide show
  1. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/PKG-INFO +1 -1
  2. byzh_core-0.0.6.0/byzh_core/Bterminal/__init__.py +7 -0
  3. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Bterminal/cmd.py +2 -2
  4. byzh_core-0.0.6.0/byzh_core/Bterminal/run_func.py +61 -0
  5. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Btqdm/my_tqdm.py +21 -8
  6. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/__init__.py +1 -1
  7. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/PKG-INFO +1 -1
  8. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/SOURCES.txt +1 -0
  9. byzh_core-0.0.4.0/byzh_core/Bterminal/__init__.py +0 -3
  10. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/LICENSE +0 -0
  11. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/README.md +0 -0
  12. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/B_os.py +0 -0
  13. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Barchive/__init__.py +0 -0
  14. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Barchive/archive.py +0 -0
  15. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Btable/__init__.py +0 -0
  16. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Btable/auto_table.py +0 -0
  17. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Btqdm/__init__.py +0 -0
  18. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Butils/__init__.py +0 -0
  19. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Butils/decorator.py +0 -0
  20. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Butils/text_style.py +0 -0
  21. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Butils/timer.py +0 -0
  22. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Bwriter/__init__.py +0 -0
  23. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/Bwriter/writer.py +0 -0
  24. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/__main__.py +0 -0
  25. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/Bconfig/__init__.py +0 -0
  26. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/Bconfig/config.py +0 -0
  27. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/__init__.py +0 -0
  28. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/auto_table.py +0 -0
  29. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/row_table.py +0 -0
  30. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core/obsolete/xy_table.py +0 -0
  31. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/dependency_links.txt +0 -0
  32. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/entry_points.txt +0 -0
  33. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/requires.txt +0 -0
  34. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/byzh_core.egg-info/top_level.txt +0 -0
  35. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/setup.cfg +0 -0
  36. {byzh_core-0.0.4.0 → byzh_core-0.0.6.0}/setup.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.4.0
3
+ Version: 0.0.6.0
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -0,0 +1,7 @@
1
+ from .cmd import b_run_cmd, b_run_python
2
+ from .run_func import b_Wrapper
3
+
4
+ __all__ = [
5
+ 'b_run_cmd', 'b_run_python',
6
+ 'b_Wrapper'
7
+ ]
@@ -60,11 +60,11 @@ def b_run_python(
60
60
 
61
61
  str_lst = args_process(args)
62
62
 
63
- print(f"{B_Color.GREEN}=====================")
63
+ print(f"{B_Color.GREEN.value}=====================")
64
64
  print("BRunPython 将在3秒后开始:")
65
65
  for string in str_lst:
66
66
  print("\t" + string)
67
- print(f"====================={B_Color.RESET}")
67
+ print(f"====================={B_Color.RESET.value}")
68
68
  time.sleep(3)
69
69
 
70
70
  for string in str_lst:
@@ -0,0 +1,61 @@
1
+ from itertools import product
2
+ from typing import Sequence, Callable, Literal
3
+ import warnings
4
+ class b_Wrapper():
5
+ def __init__(
6
+ self,
7
+ mode:Literal["product", "zip"] = "product",
8
+ **kwargs: Sequence
9
+ ):
10
+ self.mode = mode
11
+ self.keys = []
12
+
13
+ for key, value in kwargs.items():
14
+ setattr(self, key+"_list", value)
15
+ self.keys.append(key)
16
+
17
+ self.values_lst = self._get_values_lst()
18
+
19
+ def _get_values_lst(self):
20
+ temp = [getattr(self, key + "_list") for key in self.keys]
21
+ if self.mode == "product":
22
+ return list(product(*temp))
23
+ elif self.mode == "zip":
24
+ # 检查是否个数相同
25
+ if len(set(map(len, temp)))!= 1:
26
+ warnings.warn("zip模式下, 如果各部分的len不一样, 则超出部分不参与遍历")
27
+ return list(zip(*temp))
28
+ else:
29
+ raise ValueError("Invalid mode")
30
+
31
+ def _set_values(self, index):
32
+ for key, value in zip(self.keys, self.values_lst[index]):
33
+ setattr(self, key, value)
34
+
35
+ def run(self, func: Callable, *args, **kwargs):
36
+ for i in range(len(self.values_lst)):
37
+ self._set_values(i)
38
+ func(*args, **kwargs)
39
+
40
+
41
+ if __name__ == '__main__':
42
+ def demo_func():
43
+ print(f"x={wrapper.x}, y={wrapper.y}, x+y={wrapper.x + wrapper.y}")
44
+
45
+ # 示例 1: product 笛卡尔积模式
46
+ print("=== product 模式 ===")
47
+ wrapper = b_Wrapper(
48
+ mode="product",
49
+ x=[1, 2, 3],
50
+ y=[10, 20]
51
+ )
52
+ wrapper.run(demo_func)
53
+
54
+ # 示例 2: zip 模式
55
+ print("\n=== zip 模式 ===")
56
+ wrapper = b_Wrapper(
57
+ mode="zip",
58
+ x=[1, 2, 3],
59
+ y=[10, 20, 30]
60
+ )
61
+ wrapper.run(demo_func)
@@ -1,6 +1,7 @@
1
1
  import sys
2
2
  import time
3
3
  import threading
4
+ from typing import Iterable
4
5
 
5
6
  from ..Butils import B_Color, B_Appearance, B_Background
6
7
 
@@ -8,7 +9,7 @@ from ..Butils import B_Color, B_Appearance, B_Background
8
9
  class B_Tqdm:
9
10
  def __init__(
10
11
  self,
11
- total: int|None = None,
12
+ range: int|Iterable = None,
12
13
  prefix: str = 'Processing',
13
14
  suffix: str = '',
14
15
  length: int = 20,
@@ -23,7 +24,14 @@ class B_Tqdm:
23
24
  :param fill: 填充字符
24
25
  """
25
26
  super().__init__()
26
- self.total = total
27
+ self.range = range
28
+ if isinstance(range, Iterable):
29
+ self.range_len = len(range)
30
+ elif isinstance(range, int):
31
+ self.range_len = range
32
+ else:
33
+ self.range_len = None
34
+
27
35
  self.prefix = prefix
28
36
  self.suffix = suffix
29
37
  self.length = length
@@ -61,19 +69,19 @@ class B_Tqdm:
61
69
  elapsed_time = time.time() - self.start_time
62
70
  elapsed_str = self._format_time(elapsed_time)
63
71
  # 预估剩余时间
64
- if self.total is not None:
65
- estimated_time = elapsed_time / self.current * (self.total - self.current) if self.current > 0 else 0
72
+ if self.range_len is not None:
73
+ estimated_time = elapsed_time / self.current * (self.range_len - self.current) if self.current > 0 else 0
66
74
  estimated_str = self._format_time(estimated_time)
67
75
  # 计算每秒处理的项数
68
76
  speed = self.current / elapsed_time if elapsed_time > 0 else 0
69
77
 
70
78
  # 更新进度条
71
- if self.total is not None:
72
- filled_length = int(self.length * self.current // self.total)
79
+ if self.range_len is not None:
80
+ filled_length = int(self.length * self.current // self.range_len)
73
81
  bar = self.fill * filled_length + '-' * (self.length - filled_length) * len(self.fill)
74
82
 
75
83
  sys.stdout.write(f'\r{pre_show}{self.prefix} |{bar}|'
76
- f' {self.current}/{self.total} -> {elapsed_str}<{estimated_str} | {speed:.1f} it/s |'
84
+ f' {self.current}/{self.range_len} -> {elapsed_str}<{estimated_str} | {speed:.1f} it/s |'
77
85
  f' {self.suffix}{B_Color.RESET.value}')
78
86
  else:
79
87
  sys.stdout.write(f'\r{pre_show}{self.prefix} | {self.current} iters -> {elapsed_str} | {speed:.1f} it/s |'
@@ -81,6 +89,11 @@ class B_Tqdm:
81
89
  sys.stdout.flush()
82
90
 
83
91
  # 补回车
84
- if self.current == self.total:
92
+ if self.current == self.range_len:
85
93
  sys.stdout.write('\n')
86
94
  sys.stdout.flush()
95
+
96
+ def __iter__(self):
97
+ for item in self.range:
98
+ yield item
99
+ self.update()
@@ -2,4 +2,4 @@
2
2
  # class 以"B_"开头
3
3
  # function 以"b_"开头
4
4
 
5
- __version__ = '0.0.4.0'
5
+ __version__ = '0.0.6.0' # core的最后一位保持0, 留给其他包
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: byzh_core
3
- Version: 0.0.4.0
3
+ Version: 0.0.6.0
4
4
  Summary: byzh_core是byzh系列的核心库,包含了一些常用的工具函数和类。
5
5
  Author: byzh_rc
6
6
  License: MIT
@@ -16,6 +16,7 @@ byzh_core/Btable/__init__.py
16
16
  byzh_core/Btable/auto_table.py
17
17
  byzh_core/Bterminal/__init__.py
18
18
  byzh_core/Bterminal/cmd.py
19
+ byzh_core/Bterminal/run_func.py
19
20
  byzh_core/Btqdm/__init__.py
20
21
  byzh_core/Btqdm/my_tqdm.py
21
22
  byzh_core/Butils/__init__.py
@@ -1,3 +0,0 @@
1
- from .cmd import b_run_cmd, b_run_python
2
-
3
- __all__ = ['b_run_cmd', 'b_run_python']
File without changes
File without changes
File without changes
File without changes