言埠 YanPub
万言归埠,一站集成。
中文编程语言统一基础设施。一个框架,接入任意中文语言,即刻获得完整工具链。
AtomGit - 全球开发者的开源社区,开源代码托管平台
Docker 一键部署
从 gitcode 拿到 yanpub 后,三步即可启动含 11 种中文编程语言的完整环境:
git clone https://gitcode.com/skywalk163/yanpub.git cd yanpub # 1. 自动 git clone 11 种语言后端 ./deploy.sh sync # 2. 构建 Docker 镜像(默认约 3-5 分钟,纯 Python 镜像) ./deploy.sh build # 3. 启动服务 ./deploy.sh up已接入语言(11种)
| 语言 | ID | 版本 | 关键字 | 适配方式 |
|---|---|---|---|---|
| 段言 Duan | duan | 1.3.8 | 162 | 子进程 |
| 言 Yan | yan | 3.0.0 | 47 | 子进程 |
| 墨言 Moyan | moyan | 3.0.0 | 25 | 子进程 |
| 心语 Xinyu | xinyu | 1.0.0 | 46 | 子进程 |
| 知行 Zhixing | zhixing | 1.0.0 | 37 | 子进程 |
| 言律 Yanlv | yanlv | 2.0.0 | 62 | 子进程 |
| 言知 Yanzhi | yanzhi | 1.0.0 | 52 | 子进程 |
| 明道 Mingdao | mingdao | 1.0.0 | 47 | 子进程(Racket,可选) |
| 翰语 Hanyu | hanyu | 1.0.0 | 48 | 子进程(LLVM可选/Python回退) |
| 趣言 Traeyan | traeyan | 1.0.0 | 119 | 子进程 |
| 华语 Hua | hua | 0.5.0 | 69 | 子进程 |
架构
详见 DESIGN.md
yanpub ├── core/ # 核心抽象 │ ├── adapter/ # 适配器协议、注册中心、缓存、懒加载、兼容性、健康检查 │ ├── dev/ # 调试器、DAP、格式化、Linter、重构、导航 │ ├── perf/ # 基准测试、可视化、基线管理、性能分析、监控 │ ├── security/ # 沙箱、代码签名、审计 │ └── lifecycle/ # 热重载、热更新、插件、进程池、配置 ├── adapters/ # 各语言适配器(11种) ├── pkg/ # 统一包管理器(语义发布、工作空间、版本约束) ├── playground/ # 统一 Playground(协作、分享、项目、AI辅助、挑战赛) ├── lsp/ # 统一 LSP 服务(补全、导航、重构、诊断、语义高亮、折叠) ├── repl/ # 统一 REPL(友好错误提示) ├── i18n_pkg/ # 国际化(中/英/日/韩) ├── docs/ # 统一文档系统 + 语言对比 + SEO ├── cli/ # CLI 命令(24模块) └── vscode/ # VSCode 扩展CLI 命令一览
| 命令 | 说明 |
|---|---|
yanpub run <lang> <file> | 运行指定语言的代码文件 |
yanpub repl [lang] | 启动交互式 REPL |
yanpub languages | 列出所有已注册语言 |
yanpub playground | 启动在线 Playground |
yanpub lsp <lang> | 启动 LSP 服务 |
yanpub pkg install <pkg> | 安装包 |
yanpub pkg list | 列出已安装包 |
yanpub pkg search <q> | 搜索包 |
yanpub pkg publish <dir> | 发布包 |
yanpub docs | 生成文档站 |
yanpub compare | 语言对比(相似度排行 + 语法对比表) |
yanpub compare --from X --to Y | 迁移指南 |
yanpub compare <concept> | 特定概念对比 |
yanpub compare --matrix | 语法对比矩阵(15概念×10语言) |
yanpub compare --html out.html | 生成对比矩阵 HTML 页面 |
yanpub examples [lang] | 查看/运行各语言示例代码 |
yanpub examples <lang> -r <name> | 运行指定示例 |
yanpub examples -S <keyword> | 按关键字搜索示例 |
yanpub contribute <lang> | 贡献示例到指定语言(交互式向导) |
yanpub validate-examples <lang> | 验证示例元数据和代码 |
yanpub adapter create | 创建新语言适配器(交互式模板) |
yanpub adapter check <lang> | 检查适配器可发现性 |
yanpub health | 检查语言后端健康状态 |
yanpub bench | 运行性能基准测试 |
yanpub bench-visualize | 性能基准可视化(HTML 报告) |
yanpub lint | 代码风格检查 |
yanpub sandbox | 沙箱执行代码 |
yanpub sign / verify | 代码签名/验证 |
yanpub i18n | 国际化管理 |
yanpub quality [lang] | 适配器质量评分(5维度,0-100分) |
yanpub quality --html report.html | 生成质量报告 HTML |
yanpub hot-update [lang] | 适配器热更新 |
yanpub debug | 调试相关命令 |
yanpub ai | AI 辅助调试 |
yanpub refactor <lang> | 代码重构 |
yanpub workspace init | 初始化工作空间 |
yanpub workspace add <lang> | 添加语言到工作空间 |
yanpub workspace status | 查看工作空间状态 |
yanpub challenge list | 列出代码挑战赛题目 |
yanpub challenge show <id> | 查看挑战详情 |
yanpub challenge submit <id> <lang> | 提交解答 |
yanpub challenge leaderboard | 查看排行榜 |
yanpub private-registry init | 初始化私有注册中心 |
yanpub private-registry publish <dir> | 发布包 |
yanpub private-registry mirror add <name> <url> | 添加镜像 |
yanpub private-registry mirror sync <name> | 同步镜像 |
适配器开发
使用adapter create命令一键生成完整适配器目录:
yanpub adapter create # 交互式创建 yanpub adapter create mylang 0.1.0 .my # 参数式创建 yanpub adapter check mylang # 验证适配器可发现性或手动创建,最少只需 2 个文件:
adapters/mylang/ ├── adapter.yaml # 语言元信息 ├── adapter.py # 适配器实现(继承 SubprocessAdapter) └── examples/ # 示例代码(可选) └── hello.my # 带 YAML front matter最小适配器示例:
from yanpub.core.adapter import SubprocessAdapter class MyLangAdapter(SubprocessAdapter): def __init__(self): super().__init__( name="我的语言", lang_id="mylang", version="0.1.0", extensions=[".my"], run_command=["python", "-m", "mylang", "run"], keywords=["定义", "如果", "否则", "当", "返回"], primary_color="#FF6600", )适配器会被自动发现和加载,无需额外注册。详见 适配器开发指南。
示例贡献
任何人都可以为已接入语言贡献示例代码:
# 交互式创建示例(推荐) yanpub contribute duan # 参数式创建 yanpub contribute duan -n sort -t "排序" -c "打印('hi')" # 从文件读取代码 yanpub contribute duan -n hello -f code.duan # 仅预览不写入 yanpub contribute duan --dry-run # 验证已有示例 yanpub validate-examples duan私有注册中心
支持私有 Git 仓库作为包索引存储,可与公网镜像(GitHub/Gitee/GitCode)双向同步:
# 初始化私有注册中心 yanpub private-registry init --url https://git.example.com/registry.git # 发布包 yanpub private-registry publish ./my-package # 添加公网镜像(自动同步) yanpub private-registry mirror add github https://github.com/org/registry.git --direction bidirectional yanpub private-registry mirror add gitee https://gitee.com/org/registry.git --auth ssh # 同步到所有镜像 yanpub private-registry mirror sync --all # 权限管理(基于角色) yanpub private-registry permission grant alice owner yanpub private-registry permission grant bob developer --scope lang:duan4 种角色:owner(全部权限)、maintainer(发布+镜像管理)、developer(发布)、guest(只读)。
代码挑战赛
内置 6 道挑战题,支持在线评判和排行榜:
# 列出挑战 yanpub challenge list # 查看详情 yanpub challenge show hello-world # 提交解答 yanpub challenge submit hello-world duan --code '打印("你好,世界!")' yanpub challenge submit fibonacci duan -f fib.duan # 查看排行榜 yanpub challenge leaderboardPlayground 也提供 Web 界面和 API:
/challenges— 挑战赛独立页面(题目浏览/提交/排行榜)/quality— 适配器质量评分页面(5 维度进度条/等级/改进建议)/api/challenges、/api/challenges/{id}/submit、/api/leaderboard/api/quality
适配器质量评分
5 维度自动评分(总分 100),S/A/B/C/D/F 等级:
| 维度 | 满分 | 检查项 |
|---|---|---|
| 基础完整度 | 25 | adapter.py/yaml 存在、类定义、可实例化 |
| 元数据质量 | 20 | 必需字段、版本号成熟度、扩展名、颜色 |
| 示例丰富度 | 20 | 数量、front matter、多样性 |
| 文档覆盖 | 15 | README、CONTRIBUTING、关键字文档、描述 |
| 功能验证 | 20 | 关键字丰富度梯度、capabilities 覆盖、eval/run/repl 可用性 |
# 查看所有适配器评分 yanpub quality # 查看特定适配器 yanpub quality duan # 生成 HTML 报告 yanpub quality --html quality-report.html # JSON 输出 yanpub quality --json # CI 模式(生成报告文件 + 徽章数据 + PR 评论) yanpub quality --ciCI 集成:推送到 main 后自动评分并部署徽章到 gh-pages,PR 自动评论评分结果。独立quality.ymlworkflow 监听适配器变更并检测质量回归。
性能
- 启动时间 ~0.24s(10个适配器懒加载)
- 关键字首次访问 ~0.38s(动态从项目加载),缓存后 0s
调试
提示未安装doker
(base) skywalk@iZ2ze2j4cywindg339jqloZ:~/github/yanpub$ bash deploy.sh build
[ERROR] Docker 未安装,请先安装 Docker
https://docs.docker.com/get-docker/
- Docker Desktop:适用于 Windows 和 macOS 的图形界面版本
- Docker Engine:适用于 Linux 服务器的命令行版本
安装
提示failed to solve: python:3.11-slim
=> => reading from stdin 504B 0.0s
=> [internal] load build definition from Dockerfile 0.0s
=> => transferring dockerfile: 4.58kB 0.0s
=> ERROR [internal] load metadata for docker.io/library/python:3.11-slim 30.0s
------
> [internal] load metadata for docker.io/library/python:3.11-slim:
------
[+] build 0/1
⠙ Image yanpub-yanpub Building 30.3s
Dockerfile:15
--------------------
13 |
14 | # ── Stage 1: 系统依赖 + Python 包 ─────────────────────
15 | >>> FROM python:3.11-slim AS deps
16 |
17 | ENV DEBIAN_FRONTEND=noninteractive \
--------------------
failed to solve: python:3.11-slim: failed to resolve source metadata for docker.io/library/python:3.11-slim: failed to do request: Head "https://registry-1.docker.io/v2/library/python/manifests/3.11-slim": dial tcp 199.59.150.49:443: i/o timeout
内部加速
sudo mkdir -p /etc/docker sudo tee /etc/docker/daemon.json <<-'EOF' { "registry-mirrors": ["https://zf7jcpxx.mirror.aliyuncs.com"] } EOF sudo systemctl daemon-reload sudo systemctl restart docker
还是不行
使用手工下载
docker pull docker.m.daocloud.io/library/python:3.11-slim