ezKit 3.0.64__tar.gz → 3.0.65__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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.64
3
+ Version: 3.0.65
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -5,7 +5,6 @@ import subprocess
5
5
  import time
6
6
  import tomllib
7
7
  from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
8
- from copy import deepcopy
9
8
  from datetime import date, datetime, time as datetime_time, tzinfo
10
9
  from decimal import Decimal
11
10
  from functools import wraps
@@ -176,6 +175,10 @@ def check_path_type(path_object: str | Path, path_type: str) -> bool:
176
175
 
177
176
  _path_object: Path = Path(path_object) if not isinstance(path_object, Path) else path_object
178
177
 
178
+ # is_symlink 不跟随目标, 断开的符号链接也应被识别
179
+ # if path_type == "symlink":
180
+ # return _path_object.is_symlink()
181
+
179
182
  # 文件不存在的情况
180
183
  if not _path_object.exists():
181
184
  return False
@@ -402,6 +405,10 @@ def list_split(data: list, number: int, equally: bool = False) -> list | None:
402
405
 
403
406
  try:
404
407
 
408
+ # 检查 number 是否为正整数
409
+ if not isinstance(number, int) or isinstance(number, bool) or number < 1:
410
+ raise ValueError("number must be a positive integer")
411
+
405
412
  # 要将列表平均分成 n 个子列表
406
413
  if equally:
407
414
  it = iter(data)
@@ -427,6 +434,9 @@ def list_print_by_step(data: list, step: int, separator: str = " ") -> bool:
427
434
 
428
435
  try:
429
436
 
437
+ if not isinstance(step, int) or isinstance(step, bool) or step < 1:
438
+ raise ValueError("step must be a positive integer")
439
+
430
440
  # 打印
431
441
  for i, v in enumerate(data):
432
442
 
@@ -531,7 +541,7 @@ def parallelism(
531
541
  workers: int = 2,
532
542
  thread: bool = False,
533
543
  **kwargs,
534
- ) -> Any:
544
+ ) -> list | bool:
535
545
  """multi-processing or multi-threading"""
536
546
 
537
547
  # :param func: 处理函数
@@ -559,6 +569,14 @@ def parallelism(
559
569
 
560
570
  try:
561
571
 
572
+ # 确保数据不为空
573
+ if not data:
574
+ raise ValueError("data is empty")
575
+
576
+ # 检查 workers 是否为正整数
577
+ if not isinstance(workers, int) or isinstance(workers, bool) or workers < 1:
578
+ raise ValueError("workers must be a positive integer")
579
+
562
580
  # 确保并行数不超过数据量
563
581
  workers = min(len(data), workers)
564
582
  data_chunks = list_split(data, workers, equally=True) if workers > 1 else [data]
@@ -567,10 +585,10 @@ def parallelism(
567
585
  logger.info(f"{info} | data chunks error")
568
586
  return False
569
587
 
570
- # 执行多线程或多进程任务
588
+ # 在上下文管理器内获取结果, 确保任务异常由此处捕获
571
589
  pool = ThreadPoolExecutor if thread else ProcessPoolExecutor
572
590
  with pool(workers, **kwargs) as executor:
573
- return executor.map(func, data_chunks)
591
+ return list(executor.map(func, data_chunks))
574
592
 
575
593
  except Exception as e:
576
594
 
@@ -626,11 +644,15 @@ def shell(
626
644
 
627
645
  try:
628
646
 
629
- if not serialize:
647
+ options = dict(kwargs)
630
648
 
631
- return subprocess.run(args, **kwargs, check=False)
649
+ if not serialize:
650
+ return subprocess.run(args, check=options.pop("check", False), **options)
632
651
 
633
- result = subprocess.run(args, capture_output=True, text=True, check=False, **kwargs)
652
+ # 序列化模式强制使用文本输出, 同时避免重复关键字参数
653
+ options.pop("check", None)
654
+ options.update(capture_output=True, text=True)
655
+ result = subprocess.run(args, check=False, **options)
634
656
 
635
657
  return {
636
658
  "returncode": result.returncode,
@@ -709,8 +731,7 @@ def split_dict(data: dict, keys: list) -> tuple[dict[Any, Any], dict[Any, Any]]
709
731
  def sort_dicts(dicts: list[dict], key: str, *, reverse: bool = False) -> list[dict] | None:
710
732
  """字典列表排序"""
711
733
  try:
712
- new_dicts = deepcopy(dicts)
713
- return sorted(new_dicts, key=itemgetter(key), reverse=reverse)
734
+ return sorted(dicts, key=itemgetter(key), reverse=reverse)
714
735
  except Exception as e:
715
736
  if DEBUG:
716
737
  logger.exception(e)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: ezKit
3
- Version: 3.0.64
3
+ Version: 3.0.65
4
4
  Summary: Easy Kit
5
5
  Author: septvean
6
6
  Author-email: septvean@gmail.com
@@ -4,7 +4,7 @@ from setuptools import find_packages, setup
4
4
 
5
5
  setup(
6
6
  name="ezKit",
7
- version="3.0.64",
7
+ version="3.0.65",
8
8
  author="septvean",
9
9
  author_email="septvean@gmail.com",
10
10
  description="Easy Kit",
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