MCPcopy
hub / github.com/volcengine/OpenViking / main

Function main

openviking_cli/rust_cli.py:42–111  ·  view source on GitHub ↗

极简入口点:查找 ov 二进制并执行 按优先级查找: 0. Python-native 子命令(doctor) 1. ./target/release/ov(开发环境) 2. Wheel 自带:{package_dir}/openviking/bin/ov 3. PATH 查找:系统全局安装的 ov

()

Source from the content-addressed store, hash-verified

40
41
42def main():
43 """
44 极简入口点:查找 ov 二进制并执行
45
46 按优先级查找:
47 0. Python-native 子命令(doctor)
48 1. ./target/release/ov(开发环境)
49 2. Wheel 自带:{package_dir}/openviking/bin/ov
50 3. PATH 查找:系统全局安装的 ov
51 """
52 # 0. Python-native subcommands (no Rust binary needed)
53 if len(sys.argv) > 1 and sys.argv[1] == "doctor":
54 from openviking_cli.doctor import main as doctor_main
55
56 sys.exit(doctor_main())
57 # 1. 检查开发环境(仅在直接运行脚本时有效)
58 try:
59 # __file__ is openviking_cli/rust_cli.py, so parent is openviking_cli directory
60 dev_binary = Path(__file__).parent.parent / "target" / "release" / "ov"
61 if dev_binary.exists() and os.access(dev_binary, os.X_OK):
62 _exec_binary(str(dev_binary), sys.argv[1:])
63 except Exception:
64 pass
65
66 # 2. 检查 Wheel 自带(不导入 openviking,避免额外开销)
67 try:
68 # __file__ is openviking_cli/rust_cli.py, so parent is openviking_cli directory
69 package_dir = Path(__file__).parent.parent / "openviking"
70 package_bin = package_dir / "bin"
71 for binary_name in ["ov", "ov.exe"]:
72 binary = package_bin / binary_name
73 if binary.exists() and os.access(binary, os.X_OK):
74 _exec_binary(str(binary), sys.argv[1:])
75 except Exception:
76 pass
77
78 # 3. 检查 PATH,但跳过当前 Python 脚本
79 path_binary = which("ov")
80 if path_binary:
81 # 检查文件是否是 Python 脚本(避免无限循环)
82 try:
83 candidate_path = Path(path_binary).resolve()
84 with open(candidate_path, "rb") as f:
85 first_bytes = f.read(2)
86 # Skip if it starts with #! (shebang, likely Python script)
87 if first_bytes != b"#!":
88 _exec_binary(path_binary, sys.argv[1:])
89 except Exception:
90 pass
91
92 # 都找不到,提示用户
93 print(
94 """错误: 未找到 ov 二进制文件。
95
96 请选择以下方式之一安装:
97
98 1. 使用预构建 wheel(推荐):
99 pip install openviking --upgrade --force-reinstall

Callers 1

rust_cli.pyFile · 0.70

Calls 6

_exec_binaryFunction · 0.85
strFunction · 0.50
existsMethod · 0.45
accessMethod · 0.45
resolveMethod · 0.45
readMethod · 0.45

Tested by

no test coverage detected