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.
- {ezkit-3.0.64/ezKit.egg-info → ezkit-3.0.65}/PKG-INFO +1 -1
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/utils.py +30 -9
- {ezkit-3.0.64 → ezkit-3.0.65/ezKit.egg-info}/PKG-INFO +1 -1
- {ezkit-3.0.64 → ezkit-3.0.65}/setup.py +1 -1
- {ezkit-3.0.64 → ezkit-3.0.65}/LICENSE +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/MANIFEST.in +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/README.md +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/__init__.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/bandwagon.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/cipher.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/database.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/fastapix.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/http.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/markdown_to_html.template +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/markdownx.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/sendemail.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit/stock.py +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit.egg-info/SOURCES.txt +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit.egg-info/dependency_links.txt +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit.egg-info/requires.txt +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/ezKit.egg-info/top_level.txt +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/pyproject.toml +0 -0
- {ezkit-3.0.64 → ezkit-3.0.65}/setup.cfg +0 -0
|
@@ -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
|
-
) ->
|
|
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
|
-
|
|
647
|
+
options = dict(kwargs)
|
|
630
648
|
|
|
631
|
-
|
|
649
|
+
if not serialize:
|
|
650
|
+
return subprocess.run(args, check=options.pop("check", False), **options)
|
|
632
651
|
|
|
633
|
-
|
|
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
|
-
|
|
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)
|
|
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
|