打包与发布
plugin.toml 配置与 pyrsdk 打包命令。
插件开发完成后,通过 pyrsdk package 命令打包为 ZIP 文件,用户在 IDE 中选择该 ZIP 安装。
目录结构
my_plugin/
├── src/
│ ├── __main__.py # 插件入口
│ ├── plugin.toml # 插件清单(manifest v2)
│ ├── requirements.txt # 可选,第三方依赖
│ └── assets/ # 可选,只读资源
└── build/ # pyrsdk package 输出plugin.toml(manifest v2)
plugin.toml 使用 TOML 格式,根键为 manifest_version = 2。SDK 提供严格的校验(未知字段、非法值都会报错)。
顶层字段
manifest_version = 2 # 固定为 2
id = "my-plugin" # 唯一标识符,必须匹配 [A-Za-z0-9][A-Za-z0-9_-]*(:.\w+)*
name = "My Plugin" # 显示名称(必填)
version = "1.0.0" # 语义化版本号(必填)
type = "ui" # 插件类型:ui / service / data(必填)
protocol_version = 1 # 插件协议版本,固定为 1
python_version = "3.14" # 可选,目标 Python 版本
author = "Your name" # 可选,作者
description = "..." # 可选,插件描述
icons = { full = "assets/icon.png", monochrome = "assets/icon_mono.png" } # 可选激活与权限
activation_events = ["onStartup"] # 激活事件列表
permissions = ["ui.view", "file.read"] # 权限列表
platforms = ["linux", "macos", "windows", "android"] # 目标平台激活事件(activation_events):
| 事件 | 说明 |
|---|---|
onStartup | IDE 启动时自动激活 |
onView:<view_id> | 视图首次打开时激活 |
onCommand:<command_id> | 命令首次执行时激活 |
onLanguage:<language> | 打开指定语言文档时激活 |
权限(permissions):字符串列表,需从受支持集合中选择,未声明即不可用。
| 权限 | 说明 |
|---|---|
ui.view、ui.navigate、ui.notify | UI 相关 |
file.read、file.write | 本地文件 |
board.read、board.write | 设备文件 |
editor.read、editor.write | 编辑器 |
persistence.read、persistence.write | 键值存储 |
serial.read、serial.write | 串口 |
settings.read、settings.write | IDE 设置 |
tab.create、tab.manage | 标签页 |
data.read、data.write | 数据贡献 |
dialog.show | 对话框 |
runtime.inspect | 运行时检查 |
平台(platforms):windows、linux、macos、android。
contributes(贡献点)
[contributes] 声明插件向 IDE 贡献的导航容器、视图、命令、菜单和配置项。
[[contributes.navigation_containers]]
id = "my-plugin"
title = "My Plugin"
icon = { material = "extension_outlined" }
location = "primary" # primary / secondary
order = 0
when = "device.connected == true" # 可选条件表达式
[[contributes.views]]
id = "my-plugin.main"
container = "my-plugin" # 必须引用已声明的导航容器
title = "My Plugin"
renderer = "native.form" # native.tree/virtualList/table/form/markdown/log/outline/variableInspector
order = 0
when = "..."
[[contributes.commands]]
id = "my-plugin.doSomething"
title = "Do Something"
icon = { material = "play_arrow" }
[[contributes.menus]]
location = "view/title" # view/title | view/context | navigation/context | commandPalette
command = "my-plugin.doSomething"
view = "my-plugin.main" # 可选
group = "navigation" # 可选
order = 0
[[contributes.configuration]]
id = "my-plugin.interval"
title = "Poll Interval"
type = "integer"
description = "轮询间隔(毫秒)"
default = 1000
enum = [500, 1000, 2000]
order = 0- 所有贡献点 ID 必须以
插件ID.为命名空间前缀,且全局唯一。 - UI 插件必须至少声明一个
navigation_containers。 - 渲染器
rfw/rfw.*已不受支持,请改用native.*。 - 图标可用
material = "图标名"或asset = "assets/xxx.png",二者只能选一。
完整示例(UI 插件)
manifest_version = 2
id = "my-plugin"
name = "My Plugin"
version = "1.0.0"
type = "ui"
protocol_version = 1
python_version = "3.14"
author = "Your name"
description = "我的第一个插件"
activation_events = ["onStartup"]
permissions = ["ui.view", "file.read", "file.write", "settings.read"]
platforms = ["linux", "macos", "windows", "android"]
[[contributes.navigation_containers]]
id = "my-plugin"
title = "My Plugin"
icon = { material = "extension_outlined" }
[[contributes.views]]
id = "my-plugin.main"
container = "my-plugin"
title = "Main"
renderer = "native.form"
[[contributes.commands]]
id = "my-plugin.refresh"
title = "刷新"
icon = { material = "refresh" }
[[contributes.menus]]
location = "view/title"
command = "my-plugin.refresh"pyrsdk 命令
创建脚手架
pyrsdk create <ui|service|data> [目录]在当前目录(或指定目录)下创建 src/ 模板插件,包含 __main__.py 与 plugin.toml。
打包
pyrsdk package [源目录] --platform <platform> [选项]平台参数:Windows / Darwin / Linux / Android / all(all 会为所有平台逐个打包)。
常用选项:
| 选项 | 说明 |
|---|---|
-p, --platform | 目标平台(必填) |
--arch | 目标架构(如 arm64-v8a),默认全部 |
-r, --requirements | 依赖包列表(可重复) |
-rf, --requirements-file | requirements.txt 路径 |
-a, --asset | 输出路径,默认 build/<插件ID>.zip |
--exclude | 排除的相对路径列表 |
--skip-site-packages | 跳过站点包安装 |
--compile-app | 打包前编译 Python 应用代码 |
--compile-packages | 打包前编译依赖包 |
--cleanup | 清理应用和包中的无用文件 |
--cleanup-app / --cleanup-packages | 仅清理应用 / 仅清理包 |
--cleanup-app-files / --cleanup-package-files | 额外清理的 glob 列表 |
--verbose | 详细输出 |
--pip-tool uv|pip | 依赖安装工具,默认 uv |
-i, --interactive | 交互模式逐步配置 |
示例:
# 最小打包(Windows)
pyrsdk package src --platform Windows
# 指定 Python 版本(由 manifest 的 python_version 决定,也可用环境变量覆盖)
pyrsdk package src --platform Windows
# 带依赖
pyrsdk package src --platform Windows -r requests -r numpy
# 使用 requirements.txt
pyrsdk package src --platform Windows -rf requirements.txt
# Android 指定架构
pyrsdk package src --platform Android --arch arm64-v8a
# 全平台
pyrsdk package src --platform all
# 交互模式
pyrsdk package -i输出文件:build/<插件ID>.zip 及 SHA-256 校验文件 <插件ID>.zip.hash。
测试
pyrsdk test [源目录] [--raw-output]--raw-output 输出纯文本,不依赖富文本格式。
安装到 IDE
- 打开 PyriteIDE
- 进入插件页面
- 点击"注册并安装插件"
- 选择
build/目录下的 ZIP 文件 - 安装完成后插件自动启动
发布流程
- 确认
plugin.toml中的版本号已更新 - 运行
pyrsdk package打包 - 将生成的 ZIP 文件分发给用户
- 用户在 IDE 中安装
ZIP 文件不包含 Python 运行时。IDE 内嵌的 Python 运行时会执行插件代码。打包过程仅处理依赖安装和代码清理。