Skip to content

Commit 746fb6c

Browse files
committed
fix: update clippy script to use toml package for parsing Cargo.toml
1 parent c76d1f2 commit 746fb6c

File tree

1 file changed

+7
-22
lines changed

1 file changed

+7
-22
lines changed

scripts/clippy.py

Lines changed: 7 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,10 @@
88
from .setup import setup_arceos
99

1010
try:
11-
# Prefer tomllib on Python 3.11+
12-
import tomllib as _toml_impl # type: ignore
11+
# Use third-party `toml` package for parsing (keep behaviour simple)
12+
import toml as _toml_impl # type: ignore
1313
except Exception:
14-
try:
15-
import toml as _toml_impl # type: ignore
16-
except Exception:
17-
_toml_impl = None
14+
_toml_impl = None
1815

1916

2017
def main(args) -> int:
@@ -32,26 +29,14 @@ def main(args) -> int:
3229
print(f"未找到 {cargo_toml_path},无法继续")
3330
return 1
3431

35-
# 解析 Cargo.toml,优先使用 tomllib(需要以二进制打开),否则使用 toml 包
32+
# 解析 Cargo.toml,使用第三方 toml 包(文本模式)
3633
parsed = None
3734
if _toml_impl is None:
38-
print(
39-
"需要 Python 3.11 的 tomllib 或安装 python-toml 包(pip install toml)来解析 Cargo.toml"
40-
)
35+
print("需要安装 python-toml 包(pip install toml)来解析 Cargo.toml")
4136
return 1
4237
try:
43-
# 如果实现是 tomllib,需要以二进制方式读取
44-
if (
45-
getattr(_toml_impl, "loads", None) is None
46-
and getattr(_toml_impl, "load", None) is not None
47-
):
48-
# tomllib: load(fileobj) expects binary fileobj
49-
with open(cargo_toml_path, "rb") as f:
50-
parsed = _toml_impl.load(f)
51-
else:
52-
# toml (third-party) works with text
53-
with open(cargo_toml_path, "r", encoding="utf-8") as f:
54-
parsed = _toml_impl.load(f)
38+
with open(cargo_toml_path, "r", encoding="utf-8") as f:
39+
parsed = _toml_impl.load(f)
5540
except Exception as e:
5641
print(f"解析 Cargo.toml 失败: {e}")
5742
return 1

0 commit comments

Comments
 (0)