oafuncs 0.0.97.15__py3-none-any.whl → 0.0.97.16__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.
@@ -153,6 +153,7 @@ class ColorProgressBar:
153
153
  update_interval: float = 0.1,
154
154
  bar_length: int = None,
155
155
  speed_estimate_period: float = 30.0,
156
+ next_line: bool = False,
156
157
  ):
157
158
  self.iterable = iterable
158
159
  self.description = description
@@ -161,7 +162,7 @@ class ColorProgressBar:
161
162
  self.update_interval = update_interval
162
163
  self.bar_length = bar_length
163
164
  self.speed_estimate_period = speed_estimate_period
164
- self.mark_num = random.randint(0, 13) # 随机选择填充字符的数量
165
+ self.next_line = next_line
165
166
 
166
167
  # 线程安全锁
167
168
  self._lock = threading.RLock()
@@ -187,6 +188,10 @@ class ColorProgressBar:
187
188
  self._is_terminal = hasattr(self._file, "isatty") and self._file.isatty()
188
189
  self._is_jupyter = "ipykernel" in sys.modules
189
190
 
191
+ # 输出样式
192
+ filled_list = ["▊", "█", "▓", "▒", "░", "#", "=", ">", "▌", "▍", "▎", "▏", "*"]
193
+ self.filled = random.choice(filled_list)
194
+
190
195
  def _generate_gradient(self) -> Optional[List[str]]:
191
196
  """生成渐变色列表(修复内置colormap支持)"""
192
197
  try:
@@ -253,11 +258,7 @@ class ColorProgressBar:
253
258
 
254
259
  def _format_bar(self, progress: float, width: int) -> str:
255
260
  """格式化进度条显示"""
256
- filled_list = ["▊", "█", "▓", "▒", "░", "#", "=", ">", "▌", "▍", "▎", "▏", "*"]
257
- # filled = "░"
258
- # filled = filled_list[2] # 选择中间的填充字符
259
- # filled = random.choice(filled_list) # 随机选择填充字符
260
- filled = filled_list[min(self.mark_num, len(filled_list) - 1)] # 随机选择填充字符
261
+ filled = self.filled
261
262
  empty = " "
262
263
  # 为其他信息保留更多空间
263
264
  max_width = max(10, width - 60) # 至少保留10个字符的进度条
@@ -363,7 +364,10 @@ class ColorProgressBar:
363
364
  self._file.write(f"{line}\n")
364
365
  elif self._is_terminal:
365
366
  # 标准终端环境,覆盖同一行
366
- self._file.write(f"\r{line}")
367
+ if self.next_line:
368
+ self._file.write(f"\r{line}\n")
369
+ else:
370
+ self._file.write(f"\r{line}")
367
371
  else:
368
372
  # 非交互式环境,仅在完成时输出
369
373
  if self.task.finished:
@@ -395,7 +399,7 @@ class ColorProgressBar:
395
399
 
396
400
  finally:
397
401
  # 完成后进行清理
398
- if self._is_terminal and not self._is_jupyter:
402
+ if self._is_terminal and not self._is_jupyter and not self.next_line:
399
403
  self._file.write("\n")
400
404
  self._file.flush()
401
405
 
@@ -406,28 +410,46 @@ class ColorProgressBar:
406
410
  return [to_hex(cmap(i)) for i in np.linspace(0, 1, n)]
407
411
 
408
412
 
413
+ def cpbar(
414
+ iterable,
415
+ description="Working...",
416
+ total=None,
417
+ completed=0,
418
+ color="cyan",
419
+ cmap=None,
420
+ update_interval=0.1,
421
+ bar_length=None,
422
+ speed_estimate_period=30.0,
423
+ next_line=False,
424
+ ):
425
+ """便捷函数,返回 ColorProgressBar 对象"""
426
+ return ColorProgressBar(
427
+ iterable=iterable,
428
+ description=description,
429
+ total=total,
430
+ completed=completed,
431
+ color=color,
432
+ cmap=cmap,
433
+ update_interval=update_interval,
434
+ bar_length=bar_length,
435
+ speed_estimate_period=speed_estimate_period,
436
+ next_line=next_line,
437
+ )
438
+
439
+
409
440
  # 验证示例
410
441
  if __name__ == "__main__":
411
- for _ in ColorProgressBar(range(100), description="Diverging:", cmap="diverging_1"):
412
- # print("\rTesting...", end="")
442
+ for _ in cpbar(range(20), description="Diverging:", cmap="diverging_1", next_line=True):
443
+ print("Processing...")
413
444
  time.sleep(0.1)
414
445
 
415
- for _ in ColorProgressBar(range(100), description="Colorful:", cmap="colorful_1"):
416
- time.sleep(0.1)
417
-
418
- for _ in ColorProgressBar(range(100), description="Viridis:", cmap="viridis"):
446
+ for _ in ColorProgressBar(range(20), description="Viridis:", cmap="viridis"):
419
447
  time.sleep(0.1)
420
448
 
421
449
  # 使用自定义渐变色
422
450
  for _ in ColorProgressBar(range(50), description="Custom_cmap:", cmap=["#FF0000", "#0000FF"]):
423
451
  time.sleep(0.1)
424
452
 
425
- for _ in ColorProgressBar(range(50), description="Default:"):
426
- time.sleep(0.1)
427
-
428
- for _ in ColorProgressBar(range(50), description="Custom_color:", color="#FF00FF"):
429
- time.sleep(0.1)
430
-
431
453
  # 测试无法获取长度的迭代器
432
454
  def infinite_generator():
433
455
  i = 0
@@ -1097,7 +1097,7 @@ def download(var, time_s, time_e=None, lon_min=0, lon_max=359.92, lat_min=-80, l
1097
1097
  Returns:
1098
1098
  None
1099
1099
  """
1100
- from oafuncs.oa_data import pbar
1100
+ from oafuncs.oa_tool import pbar
1101
1101
  from oafuncs.oa_cmap import get as get_cmap
1102
1102
 
1103
1103
  _get_initial_data()
oafuncs/oa_tool.py CHANGED
@@ -1,21 +1,8 @@
1
- #!/usr/bin/env python
2
- # coding=utf-8
3
- """
4
- Author: Liu Kun && 16031215@qq.com
5
- Date: 2025-04-04 20:17:42
6
- LastEditors: Liu Kun && 16031215@qq.com
7
- LastEditTime: 2025-04-04 20:17:45
8
- FilePath: \\Python\\My_Funcs\\OAFuncs\\oafuncs\\oa_tool.py
9
- Description:
10
- EditPlatform: vscode
11
- ComputerInfo: XPS 15 9510
12
- SystemInfo: Windows 11
13
- Python Version: 3.12
14
- """
15
- from typing import Iterable
1
+ from typing import Any, Iterable, List, Optional, Union
16
2
 
17
3
  __all__ = ["PEx", "email", "pbar"]
18
4
 
5
+
19
6
  class PEx:
20
7
  """
21
8
  PEx 封装了 ParallelExecutor,
@@ -37,7 +24,7 @@ class PEx:
37
24
 
38
25
  def __init__(self, *args, **kwargs):
39
26
  """
40
- 初始化 PEx 实例,内部创建一个 ParallelExecutor 实例。
27
+ 初始化 PEx 实例,内部创建一个 ParallelExecutor 实例
41
28
 
42
29
  参数:
43
30
  *args: 传递给 ParallelExecutor 的位置参数。
@@ -47,7 +34,7 @@ class PEx:
47
34
 
48
35
  def __getattr__(self, attr):
49
36
  """
50
- 将所有未定义的属性访问委托给内部的 ParallelExecutor 实例。
37
+ 将所有未定义的属性访问委托给内部的 ParallelExecutor 实例
51
38
 
52
39
  参数:
53
40
  attr (str): 要访问的属性名称。
@@ -58,26 +45,36 @@ class PEx:
58
45
  return getattr(self.executor, attr)
59
46
 
60
47
 
61
- def email(title="Title", content=None, send_to="16031215@qq.com"):
48
+ def email(title="Title", content=None, send_to="10001@qq.com"):
62
49
  from ._script.email import send
50
+
63
51
  send(title, content, send_to)
64
52
 
65
53
 
66
- def pbar(iterable: Iterable, description: str = "Working ...", color: str = "cyan", cmap: str = None, lupdate_interval: float = 0.1, bar_length: int = None, **kwargs) -> Iterable:
67
- """
68
- 快速创建进度条的封装函数
69
- :param iterable: 可迭代对象
70
- :param prefix: 进度条前缀
71
- :param color: 基础颜色
72
- :param cmap: 渐变色名称
73
- :param kwargs: 其他ColorProgressBar支持的参数
74
-
75
- example:
76
- from oafuncs.oa_data import pbar
77
- from time import sleep
78
- for i in pbar(range(100), prefix="Processing", color="green", cmap="viridis"):
79
- sleep(0.1)
80
- """
54
+ def pbar(
55
+ iterable: Iterable=range(100),
56
+ description: str = "Working...",
57
+ total: Optional[float] = None,
58
+ completed: float = 0,
59
+ color: Any = "cyan",
60
+ cmap: Union[str, List[str], None] = None,
61
+ update_interval: float = 0.1,
62
+ bar_length: Optional[int] = None,
63
+ speed_estimate_period: float = 30.0,
64
+ next_line: bool = False,
65
+ ):
81
66
  from ._script.cprogressbar import ColorProgressBar
82
67
 
83
- return ColorProgressBar(iterable=iterable, description=description, color=color, cmap=cmap, update_interval=lupdate_interval, bar_length=bar_length, **kwargs)
68
+ """便捷函数,返回 ColorProgressBar 对象"""
69
+ return ColorProgressBar(
70
+ iterable=iterable,
71
+ description=description,
72
+ total=total,
73
+ completed=completed,
74
+ color=color,
75
+ cmap=cmap,
76
+ update_interval=update_interval,
77
+ bar_length=bar_length,
78
+ speed_estimate_period=speed_estimate_period,
79
+ next_line=next_line,
80
+ )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: oafuncs
3
- Version: 0.0.97.15
3
+ Version: 0.0.97.16
4
4
  Summary: Oceanic and Atmospheric Functions
5
5
  Home-page: https://github.com/Industry-Pays/OAFuncs
6
6
  Author: Kun Liu
@@ -7,10 +7,10 @@ oafuncs/oa_file.py,sha256=HqbB0kumd--71tMQZJUTBruNNtsGOotg77w-C7yBa0k,16524
7
7
  oafuncs/oa_help.py,sha256=loyzTbjU_0VpSIBvAEUA_tqxG8MVsO0xFE_2hgQ3zMw,4188
8
8
  oafuncs/oa_nc.py,sha256=1TIH892HmBbZKOjoW7XtP60T3lL0Tjhyq5yOWd12C1U,10423
9
9
  oafuncs/oa_python.py,sha256=tSRSFeTm4TicSzZeyUhlMWUy8rSrKGTRv4CqbrwfF64,4141
10
- oafuncs/oa_tool.py,sha256=8B2cyZ4l3XrWbDMkMKAlvWaiQGP_FKLKVJaqbu6G4uU,2782
10
+ oafuncs/oa_tool.py,sha256=xkwJMiTu5dVCYmHNuGmW7526JHTaE7TnFlqvWl1cfD8,2438
11
11
  oafuncs/_data/OAFuncs.png,sha256=y1_x-mUP3gFjcy6m8FqfvQO_HgjzPhQKfXjnSHjslZE,3436152
12
12
  oafuncs/_data/hycom_3hourly.png,sha256=azt_uPcXtl_8CSKRLLPCIf5pPrcxMiOzvoFQnwb0zUo,12411415
13
- oafuncs/_script/cprogressbar.py,sha256=bDIb99JqCHwIZKsrRXLfqiArTuNUuG9GyestphJM43I,15491
13
+ oafuncs/_script/cprogressbar.py,sha256=wRU3SFPFtMI7ER26tTzg223kVKNo5RDWE9CzdIgUsuE,15771
14
14
  oafuncs/_script/email.py,sha256=lL4HGKrr524-g0xLlgs-4u7x4-u7DtgNoD9AL8XJKj4,3058
15
15
  oafuncs/_script/netcdf_merge.py,sha256=_EPF9Xj4HOVC9sZpi1lt62-Aq6pMlgsgwaajEBLhW6g,5092
16
16
  oafuncs/_script/netcdf_modify.py,sha256=kjdAOb1iy57u8nDN-eEFTti149vfhGMY-36v-b2FtII,4224
@@ -21,7 +21,7 @@ oafuncs/_script/plot_dataset.py,sha256=zkSEnO_-biyagorwWXPoihts_cwuvripzEt-l9bHJ
21
21
  oafuncs/_script/replace_file_concent.py,sha256=eCFZjnZcwyRvy6b4mmIfBna-kylSZTyJRfgXd6DdCjk,5982
22
22
  oafuncs/oa_down/User_Agent-list.txt,sha256=pazxSip8_lphEBOPHG902zmIBUg8sBKXgmqp_g6j_E4,661062
23
23
  oafuncs/oa_down/__init__.py,sha256=kRX5eTUCbAiz3zTaQM1501paOYS_3fizDN4Pa0mtNUA,585
24
- oafuncs/oa_down/hycom_3hourly.py,sha256=YtRgz4b7MBd2VjpPU-jIyvYn-PYQDgO20jHUMdxEyi0,64471
24
+ oafuncs/oa_down/hycom_3hourly.py,sha256=YL6zcKdyz4Hkv8703z5mAqgtQ8c8g3oHivcsrc8uISQ,64471
25
25
  oafuncs/oa_down/idm.py,sha256=6eKsbGZ91_187_jJawUc6lqKRdUTse6EfUJnlaSl5mo,1903
26
26
  oafuncs/oa_down/literature.py,sha256=2bF9gSKQbzcci9LcKE81j8JEjIJwON7jbwQB3gDDA3E,11331
27
27
  oafuncs/oa_down/test_ua.py,sha256=0IQq3NjqfNr7KkyjS_U-a4mYu-r-E7gzawwo4IfEa6Y,10851
@@ -35,8 +35,8 @@ oafuncs/oa_sign/__init__.py,sha256=QKqTFrJDFK40C5uvk48GlRRbGFzO40rgkYwu6dYxatM,5
35
35
  oafuncs/oa_sign/meteorological.py,sha256=8091SHo2L8kl4dCFmmSH5NGVHDku5i5lSiLEG5DLnOQ,6489
36
36
  oafuncs/oa_sign/ocean.py,sha256=xrW-rWD7xBWsB5PuCyEwQ1Q_RDKq2KCLz-LOONHgldU,5932
37
37
  oafuncs/oa_sign/scientific.py,sha256=a4JxOBgm9vzNZKpJ_GQIQf7cokkraV5nh23HGbmTYKw,5064
38
- oafuncs-0.0.97.15.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
39
- oafuncs-0.0.97.15.dist-info/METADATA,sha256=x5VvCFth9kK0pT_sNmMq4xublar8wHVWkP3vJShEqdg,4226
40
- oafuncs-0.0.97.15.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
41
- oafuncs-0.0.97.15.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
42
- oafuncs-0.0.97.15.dist-info/RECORD,,
38
+ oafuncs-0.0.97.16.dist-info/licenses/LICENSE.txt,sha256=rMtLpVg8sKiSlwClfR9w_Dd_5WubTQgoOzE2PDFxzs4,1074
39
+ oafuncs-0.0.97.16.dist-info/METADATA,sha256=TYq3D0b7ZU9AzUZnQ9HEg3bdQI_cV-4e5wIoWXXwzuY,4226
40
+ oafuncs-0.0.97.16.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
41
+ oafuncs-0.0.97.16.dist-info/top_level.txt,sha256=bgC35QkXbN4EmPHEveg_xGIZ5i9NNPYWqtJqaKqTPsQ,8
42
+ oafuncs-0.0.97.16.dist-info/RECORD,,