ygo 1.1.3__py3-none-any.whl → 1.1.5__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.
Potentially problematic release.
This version of ygo might be problematic. Click here for more details.
- ygo/__init__.py +4 -2
- ygo/lazy.py +47 -0
- ygo/utils.py +37 -3
- {ygo-1.1.3.dist-info → ygo-1.1.5.dist-info}/METADATA +2 -1
- ygo-1.1.5.dist-info/RECORD +13 -0
- ylog/__init__.py +1 -1
- ylog/core.py +2 -2
- ygo-1.1.3.dist-info/RECORD +0 -12
- {ygo-1.1.3.dist-info → ygo-1.1.5.dist-info}/WHEEL +0 -0
- {ygo-1.1.3.dist-info → ygo-1.1.5.dist-info}/licenses/LICENSE +0 -0
- {ygo-1.1.3.dist-info → ygo-1.1.5.dist-info}/top_level.txt +0 -0
ygo/__init__.py
CHANGED
|
@@ -19,8 +19,9 @@ from .utils import (
|
|
|
19
19
|
module_from_str,
|
|
20
20
|
fn_from_str,
|
|
21
21
|
)
|
|
22
|
+
from .lazy import lazy_import
|
|
22
23
|
|
|
23
|
-
__version__ = "v1.1.
|
|
24
|
+
__version__ = "v1.1.5"
|
|
24
25
|
|
|
25
26
|
__all__ = [
|
|
26
27
|
"FailTaskError",
|
|
@@ -33,5 +34,6 @@ __all__ = [
|
|
|
33
34
|
"fn_info",
|
|
34
35
|
"fn_from_str",
|
|
35
36
|
"module_from_str",
|
|
36
|
-
"pool"
|
|
37
|
+
"pool",
|
|
38
|
+
"lazy_import"
|
|
37
39
|
]
|
ygo/lazy.py
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
"""
|
|
3
|
+
---------------------------------------------
|
|
4
|
+
Copyright (c) 2025 ZhangYundi
|
|
5
|
+
Licensed under the MIT License.
|
|
6
|
+
Created on 2025/6/29 10:36
|
|
7
|
+
Email: yundi.xxii@outlook.com
|
|
8
|
+
Description:
|
|
9
|
+
---------------------------------------------
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from typing import Any
|
|
13
|
+
from hydra._internal.utils import _locate
|
|
14
|
+
|
|
15
|
+
class LazyImport:
|
|
16
|
+
def __init__(self, full_name: str):
|
|
17
|
+
self._full_name = full_name
|
|
18
|
+
self._obj = None
|
|
19
|
+
|
|
20
|
+
def _load(self) -> Any:
|
|
21
|
+
if self._obj is None:
|
|
22
|
+
self._obj = _locate(self._full_name)
|
|
23
|
+
return self._obj
|
|
24
|
+
|
|
25
|
+
def __getattr__(self, attr: str) -> Any:
|
|
26
|
+
obj = self._load()
|
|
27
|
+
return getattr(obj, attr)
|
|
28
|
+
|
|
29
|
+
def __dir__(self) -> list[str]:
|
|
30
|
+
obj = self._load()
|
|
31
|
+
return dir(obj)
|
|
32
|
+
|
|
33
|
+
def __call__(self, *args, **kwargs) -> Any:
|
|
34
|
+
obj = self._load()
|
|
35
|
+
if isinstance(obj, type):
|
|
36
|
+
return obj(*args, **kwargs)
|
|
37
|
+
elif callable(obj):
|
|
38
|
+
return obj(*args, **kwargs)
|
|
39
|
+
else:
|
|
40
|
+
raise TypeError(f"The target `{self._full_name}` is not callable or instantiable.")
|
|
41
|
+
|
|
42
|
+
def __repr__(self):
|
|
43
|
+
return f"<LazyImport '{self._full_name}'>"
|
|
44
|
+
|
|
45
|
+
def lazy_import(full_name: str):
|
|
46
|
+
"""实现模块和方法的懒加载"""
|
|
47
|
+
return LazyImport(full_name)
|
ygo/utils.py
CHANGED
|
@@ -9,10 +9,44 @@ Created on 2025/5/26 23:31
|
|
|
9
9
|
|
|
10
10
|
import inspect
|
|
11
11
|
import os
|
|
12
|
+
from functools import wraps
|
|
12
13
|
from pathlib import Path
|
|
13
|
-
|
|
14
|
+
import warnings
|
|
14
15
|
from .delay import delay
|
|
15
16
|
|
|
17
|
+
def deprecated(use_instead: str = None):
|
|
18
|
+
"""
|
|
19
|
+
标记方法为弃用
|
|
20
|
+
|
|
21
|
+
Parameters
|
|
22
|
+
----------
|
|
23
|
+
use_instead: str
|
|
24
|
+
推荐替代使用的方法或者类名称
|
|
25
|
+
Returns
|
|
26
|
+
-------
|
|
27
|
+
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def decorator(func):
|
|
31
|
+
"""
|
|
32
|
+
装饰器
|
|
33
|
+
Parameters
|
|
34
|
+
----------
|
|
35
|
+
func: callable
|
|
36
|
+
被装饰的函数
|
|
37
|
+
Returns
|
|
38
|
+
-------
|
|
39
|
+
|
|
40
|
+
"""
|
|
41
|
+
@wraps(func)
|
|
42
|
+
def wrapper(*args, **kwargs):
|
|
43
|
+
msg = f"`{func.__name__}` is deprecated. "
|
|
44
|
+
if use_instead:
|
|
45
|
+
msg += f"Please use `{use_instead}` instead."
|
|
46
|
+
warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
|
|
47
|
+
return func(*args, **kwargs)
|
|
48
|
+
return wrapper
|
|
49
|
+
return decorator
|
|
16
50
|
|
|
17
51
|
def fn_params(func: callable):
|
|
18
52
|
"""
|
|
@@ -111,7 +145,7 @@ def fn_info(fn: callable) -> str:
|
|
|
111
145
|
"""
|
|
112
146
|
return s
|
|
113
147
|
|
|
114
|
-
|
|
148
|
+
@deprecated("lazy_import")
|
|
115
149
|
def fn_from_str(s):
|
|
116
150
|
"""
|
|
117
151
|
字符串导入对应fn
|
|
@@ -128,7 +162,7 @@ def fn_from_str(s):
|
|
|
128
162
|
_callable = getattr(mod, func)
|
|
129
163
|
return _callable
|
|
130
164
|
|
|
131
|
-
|
|
165
|
+
@deprecated("lazy_import")
|
|
132
166
|
def module_from_str(s):
|
|
133
167
|
"""字符串导入模块"""
|
|
134
168
|
import importlib
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: ygo
|
|
3
|
-
Version: 1.1.
|
|
3
|
+
Version: 1.1.5
|
|
4
4
|
Summary: 一个轻量级 Python 工具包,支持 并发执行(带进度条)、延迟调用、链式绑定参数、函数信息获取、模块/函数动态加载。并结合 ylog 提供日志记录能力
|
|
5
5
|
Project-URL: homepage, https://github.com/link-yundi/ygo
|
|
6
6
|
Project-URL: repository, https://github.com/link-yundi/ygo
|
|
7
7
|
Requires-Python: >=3.12
|
|
8
8
|
Description-Content-Type: text/markdown
|
|
9
9
|
License-File: LICENSE
|
|
10
|
+
Requires-Dist: hydra-core>=1.3.2
|
|
10
11
|
Requires-Dist: joblib>=1.5.0
|
|
11
12
|
Requires-Dist: loguru>=0.7.3
|
|
12
13
|
Requires-Dist: tqdm>=4.67.1
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
ygo/__init__.py,sha256=ZxDlB9CV07FoZj-4UpQlu3JM31b4Y1IuxYhr4v8PliI,728
|
|
2
|
+
ygo/delay.py,sha256=66xtPXqyD630FL7LWL5qJKAIZvyGDwZyM4qPfk8Czlg,2206
|
|
3
|
+
ygo/exceptions.py,sha256=0OYDYt_9KKo8mF2XBG5QkCMr3-ASp69VDSPOEwlIsrI,660
|
|
4
|
+
ygo/lazy.py,sha256=09ia9rSGPjzUy633aFvM5NZJYdUdc8-IfSZnKSmeb10,1285
|
|
5
|
+
ygo/pool.py,sha256=bnHm4TtnRoFBv5UvV7WpuObJoK4FdoRf65mvf82yEyI,7052
|
|
6
|
+
ygo/utils.py,sha256=paeYb8TwonIaDwusE6YV9v_-Y-WzVjGgSa_c1mblw3Y,4040
|
|
7
|
+
ygo-1.1.5.dist-info/licenses/LICENSE,sha256=6AKUWQ1xe-jwPSFv_H6FMQLNNWb7AYqzuEUTwlP2S8M,1067
|
|
8
|
+
ylog/__init__.py,sha256=S_M_Hv_gKI_U9XUNn3rCu5h9NHZndVMRfRjMs2sjHyw,452
|
|
9
|
+
ylog/core.py,sha256=l8vrSgCLQGIeQN_mqw8rMNp3W7m41nqJIH48DHtW16c,9105
|
|
10
|
+
ygo-1.1.5.dist-info/METADATA,sha256=g7xomDtsCM6Re1HxbYI9NBg6dv5jvRyujm6391mYWc0,4877
|
|
11
|
+
ygo-1.1.5.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
12
|
+
ygo-1.1.5.dist-info/top_level.txt,sha256=sY7lJBJ2ncfEMAxoNBVay0RVUixpVt9Osuwwy0_uWqU,9
|
|
13
|
+
ygo-1.1.5.dist-info/RECORD,,
|
ylog/__init__.py
CHANGED
ylog/core.py
CHANGED
|
@@ -80,7 +80,7 @@ class _Logger:
|
|
|
80
80
|
|
|
81
81
|
logger.add(
|
|
82
82
|
sys.stderr,
|
|
83
|
-
level="
|
|
83
|
+
level="TRACE",
|
|
84
84
|
format=console_format,
|
|
85
85
|
colorize=True,
|
|
86
86
|
backtrace=self.debug_mode,
|
|
@@ -131,7 +131,7 @@ class _Logger:
|
|
|
131
131
|
# 错误级别以下的日志
|
|
132
132
|
logger.add(
|
|
133
133
|
str(info_log_file),
|
|
134
|
-
level="
|
|
134
|
+
level="TRACE",
|
|
135
135
|
format=common_format,
|
|
136
136
|
rotation=levels["INFO"]["rotation"],
|
|
137
137
|
retention=levels["INFO"]["retention"],
|
ygo-1.1.3.dist-info/RECORD
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
ygo/__init__.py,sha256=S9SCbzb5qENx85ZA39Qrszi2PQfaJgqy-8JUnmRtgas,679
|
|
2
|
-
ygo/delay.py,sha256=66xtPXqyD630FL7LWL5qJKAIZvyGDwZyM4qPfk8Czlg,2206
|
|
3
|
-
ygo/exceptions.py,sha256=0OYDYt_9KKo8mF2XBG5QkCMr3-ASp69VDSPOEwlIsrI,660
|
|
4
|
-
ygo/pool.py,sha256=bnHm4TtnRoFBv5UvV7WpuObJoK4FdoRf65mvf82yEyI,7052
|
|
5
|
-
ygo/utils.py,sha256=c-g4fJgeZp8diinkJhX4DAJBZEhH2tHYniUzRlt1EgU,3178
|
|
6
|
-
ygo-1.1.3.dist-info/licenses/LICENSE,sha256=6AKUWQ1xe-jwPSFv_H6FMQLNNWb7AYqzuEUTwlP2S8M,1067
|
|
7
|
-
ylog/__init__.py,sha256=KbpLoLDwpA-h3E1jkZy7_g8zKY2B8V0BRylB-xVcHB0,452
|
|
8
|
-
ylog/core.py,sha256=CFvjqskQtOkmiGUS6oUUTOr_RYHahlGRZ6gycL-vPrs,9135
|
|
9
|
-
ygo-1.1.3.dist-info/METADATA,sha256=hTyKyyKNFySgZiDEU4fGnPinDcMDC7l2-xTSauVR0Ns,4844
|
|
10
|
-
ygo-1.1.3.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
|
|
11
|
-
ygo-1.1.3.dist-info/top_level.txt,sha256=sY7lJBJ2ncfEMAxoNBVay0RVUixpVt9Osuwwy0_uWqU,9
|
|
12
|
-
ygo-1.1.3.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|