阶段4(上):LangGraph、Function Calling、MCP(SDK 2.x)、Agent 评测与运维、Agent 设计专题;run_examples 设置 RUN_EXAMPLES=1
This commit is contained in:
1 parent
6650f7eb6d
commit
caaec830b3
38 files changed
+3515
-64
No files matched your search
@@ -5,6 +5,7 @@
|
||||
- Python:*.py 直接运行(文件开头可写 `# requires: 包1, 包2`,缺包时跳过);test_*.py 用 pytest 运行
|
||||
- TypeScript:*.ts 用 Node.js 直接运行(需要 Node 23.6+ 的类型剥离,推荐 Node 24 LTS)
|
||||
- 文件开头写 `# 不自动运行` / `// 不自动运行` 的跳过(需要外部服务的示例)
|
||||
- 运行时设置环境变量 `RUN_EXAMPLES=1`:会长期运行的服务(如 MCP stdio 服务)据此只做导入检查、不启动
|
||||
|
||||
用法:python3 tools/run_examples.py [路径过滤关键词]
|
||||
"""
|
||||
@@ -24,7 +25,7 @@ ROOT = Path(__file__).resolve().parents[1]
|
||||
def run(cmd: list[str] | str, cwd: Path, timeout: int = 180) -> tuple[bool, str]:
|
||||
try:
|
||||
p = subprocess.run(cmd, cwd=cwd, shell=isinstance(cmd, str), capture_output=True, text=True, timeout=timeout,
|
||||
env={**os.environ, "PYTHONPATH": str(cwd)})
|
||||
env={**os.environ, "PYTHONPATH": str(cwd), "RUN_EXAMPLES": "1"}, stdin=subprocess.DEVNULL)
|
||||
return p.returncode == 0, (p.stdout + p.stderr)[-1500:]
|
||||
except subprocess.TimeoutExpired:
|
||||
return False, "超时"
|
||||
|
||||
Reference in new issue
Block a user