mirror of
https://github.com/dptech-corp/Uni-Lab-OS.git
synced 2026-02-04 21:35:09 +00:00
Adjust log level & Add workbench virtual example & Add not action decorator & Add check_mode &
This commit is contained in:
@@ -182,3 +182,49 @@ def get_all_subscriptions(instance) -> list:
|
||||
except Exception:
|
||||
pass
|
||||
return subscriptions
|
||||
|
||||
|
||||
def not_action(func: F) -> F:
|
||||
"""
|
||||
标记方法为非动作的装饰器
|
||||
|
||||
用于装饰 driver 类中的方法,使其在 complete_registry 时不被识别为动作。
|
||||
适用于辅助方法、内部工具方法等不应暴露为设备动作的公共方法。
|
||||
|
||||
Example:
|
||||
class MyDriver:
|
||||
@not_action
|
||||
def helper_method(self):
|
||||
# 这个方法不会被注册为动作
|
||||
pass
|
||||
|
||||
def actual_action(self, param: str):
|
||||
# 这个方法会被注册为动作
|
||||
self.helper_method()
|
||||
|
||||
Note:
|
||||
- 可以与其他装饰器组合使用,@not_action 应放在最外层
|
||||
- 仅影响 complete_registry 的动作识别,不影响方法的正常调用
|
||||
"""
|
||||
|
||||
@wraps(func)
|
||||
def wrapper(*args, **kwargs):
|
||||
return func(*args, **kwargs)
|
||||
|
||||
# 在函数上附加标记
|
||||
wrapper._is_not_action = True # type: ignore[attr-defined]
|
||||
|
||||
return wrapper # type: ignore[return-value]
|
||||
|
||||
|
||||
def is_not_action(func) -> bool:
|
||||
"""
|
||||
检查函数是否被标记为非动作
|
||||
|
||||
Args:
|
||||
func: 被检查的函数
|
||||
|
||||
Returns:
|
||||
如果函数被 @not_action 装饰则返回 True,否则返回 False
|
||||
"""
|
||||
return getattr(func, "_is_not_action", False)
|
||||
|
||||
@@ -28,6 +28,7 @@ __all__ = [
|
||||
from ast import Constant
|
||||
|
||||
from unilabos.utils import logger
|
||||
from unilabos.utils.decorator import is_not_action
|
||||
|
||||
|
||||
class ImportManager:
|
||||
@@ -275,6 +276,9 @@ class ImportManager:
|
||||
method_info = self._analyze_method_signature(method)
|
||||
result["status_methods"][actual_name] = method_info
|
||||
elif not name.startswith("_"):
|
||||
# 检查是否被 @not_action 装饰器标记
|
||||
if is_not_action(method):
|
||||
continue
|
||||
# 其他非_开头的方法归类为action
|
||||
method_info = self._analyze_method_signature(method)
|
||||
result["action_methods"][name] = method_info
|
||||
@@ -330,6 +334,9 @@ class ImportManager:
|
||||
if actual_name not in result["status_methods"]:
|
||||
result["status_methods"][actual_name] = method_info
|
||||
else:
|
||||
# 检查是否被 @not_action 装饰器标记
|
||||
if self._is_not_action_method(node):
|
||||
continue
|
||||
# 其他非_开头的方法归类为action
|
||||
result["action_methods"][method_name] = method_info
|
||||
return result
|
||||
@@ -450,6 +457,13 @@ class ImportManager:
|
||||
return True
|
||||
return False
|
||||
|
||||
def _is_not_action_method(self, node: ast.FunctionDef) -> bool:
|
||||
"""检查是否是@not_action装饰的方法"""
|
||||
for decorator in node.decorator_list:
|
||||
if isinstance(decorator, ast.Name) and decorator.id == "not_action":
|
||||
return True
|
||||
return False
|
||||
|
||||
def _get_property_name_from_setter(self, node: ast.FunctionDef) -> str:
|
||||
"""从setter装饰器中获取属性名"""
|
||||
for decorator in node.decorator_list:
|
||||
|
||||
Reference in New Issue
Block a user