← 提示词库 Anthropic/claude-code/skills/run/examples/library.md 原文 md
🌐 中英双语对照

Example: Library / SDK / 示例:库 / SDK

Libraries don't have a "run" step in the process sense - there's no
server to start, no CLI to invoke. For libraries, the run skill is about:

库在流程意义上没有"运行"环节——没有需要启动的服务器,也没有需要调用的 CLI。对库而言,run 技能的内容是:

  1. Building the library from source
  2. 从源码构建该库
  3. Running the test suite
  4. 运行测试套件
  5. A minimal working example that exercises the library and proves
    it's installed correctly
  6. 一个能实际调用该库并证明其安装正确的最小可运行示例

Keep it brief. The template's Build and Test sections do most of the work.

保持简短。模板的 Build 和 Test 部分已承担大部分工作。

The smoke-test example / 冒烟测试示例

The main library-specific addition is a tiny program (or REPL snippet)
that imports the library and does one real thing. This is how an agent
confirms "yes, the library is usable":

最主要的库特定补充内容是一个小程序(或 REPL 片段),它导入该库并完成一件真实的事情。这就是代理确认"是的,这个库可用"的方式:

Verify

验证

python -c '
from mylib import Client
c = Client()
print(c.ping())
'
# -> pong

Or for a compiled language:

对于编译型语言:

cat > /tmp/smoke.go <<GO
package main
import "example.com/mylib"
func main() { println(mylib.Version()) }
GO
go run /tmp/smoke.go
# -> v1.2.3

Example snippet / 示例片段


name: run-mylib
description: Build, install, and test mylib from source. Use when asked to verify mylib works, run its tests, or build a distribution.

mylib is a Python library - "running" it means building from source
and executing the test suite.

mylib 是一个 Python 库——"运行"它意味着从源码构建并执行测试套件。

Setup

环境配置

pip install -e '.[dev]'

Verify

验证

python -c 'import mylib; print(mylib.__version__)'
# -> 2.1.0

Test

测试

pytest

Subset of tests: pytest tests/unit/. With coverage: pytest --cov=mylib.

测试子集:pytest tests/unit/。带覆盖率:pytest --cov=mylib。

Build (distribution)

构建(发行包)

pip install build
python -m build
# -> dist/mylib-2.1.0-py3-none-any.whl

Things to consider documenting / 值得记录的内容