8
8
from .setup import setup_arceos
9
9
10
10
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
13
13
except Exception :
14
- try :
15
- import toml as _toml_impl # type: ignore
16
- except Exception :
17
- _toml_impl = None
14
+ _toml_impl = None
18
15
19
16
20
17
def main (args ) -> int :
@@ -32,26 +29,14 @@ def main(args) -> int:
32
29
print (f"未找到 { cargo_toml_path } ,无法继续" )
33
30
return 1
34
31
35
- # 解析 Cargo.toml,优先使用 tomllib(需要以二进制打开),否则使用 toml 包
32
+ # 解析 Cargo.toml,使用第三方 toml 包(文本模式)
36
33
parsed = None
37
34
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" )
41
36
return 1
42
37
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 )
55
40
except Exception as e :
56
41
print (f"解析 Cargo.toml 失败: { e } " )
57
42
return 1
0 commit comments