tos.py 是什么
激活 TuyaOpen 后,tos.py 即在 PATH 中。它将项目配置、编译系统、烧录与日志监听封装为一组子命令。随时运行 tos.py --help 查看列表。
- 所有命令都需在应用项目目录中执行 ——
config、build、clean、flash、monitor均如此。 - 首次
build会将工具链下载到platform/,比后续编译慢。 - 每次打开新终端都需重新激活
tos.py(Linux/Mac 用. ./export.sh,Windows 用.\export.ps1)。
环境与校验
tos.py version❯ tos.py version
[INFO]: v1.3.0-23-g6bcb5aa查看当前 tag-commit。[Unknown version] 表示仓库无 tag(常见于 fork)。
tos.py check❯ tos.py check
[INFO]: [git] (2.43.0 >= 2.0.0) is ok.
...安装或拉取后使用 —— 校验 git/cmake/make/ninja 版本并执行 git submodule update --init。
配置项目
以下命令用于选择或调整开发板配置。所选配置写入 app_default.config;choice 与 menu 均会先深度清理,因为可能切换工具链。
tos.py config choice❯ tos.py config choice
1. T5AI.config
2. ESP32.config
...
Choice config file:为当前项目选择已验证的开发板配置。
tos.py config menutos.py config menu # 打开可视化 Kconfig 菜单交互调整 Kconfig 选项,在菜单内保存。
tos.py config save❯ tos.py config save
Input save config name:将当前经 menu 调整的配置保存为项目 config/ 目录下的具名配置。
编译与清理
tos.py build [-v]❯ tos.py build
...
[INFO]: ******* Build Success ********将项目编译为 .build/bin 中可烧录的 bin。-v 输出详细日志。
tos.py clean [-f]❯ tos.py clean -f
[INFO]: Fullclean success.清理编译缓存。-f 在 ninja clean 后删除 .build 进行深度清理。
烧录与监听
tos.py flash [-p PORT] [-b BAUD]❯ tos.py flash
...
[INFO]: Flash write success.将编译好的 bin 写入设备。省略 -p 可从列表选择串口。
tos.py monitor [-p PORT] [-b BAUD]❯ tos.py monitor
[INFO]: Open Monitor. (Quit: Ctrl+c)实时输出设备串口日志。按 Ctrl+C 再按回车退出;也可用于写入授权码。
工作流与脚手架
tos.py updatetos.py update在主仓库 git pull/git checkout 后使用 —— 按 platform/platform_config.yaml 切换依赖到指定 commit。
tos.py new [--framework base|arduino]tos.py new # 提示输入项目名,复制模板从 tools/app_template/ 脚手架新建用户应用(base 或 arduino 框架)。
tos.py dev bac [-d DIST] [-o LOGDIR]tos.py dev bac # 编译 config/(或 boards/)中的每个配置批量编译:遍历每个 .config,每次构建间深度清理,可选将 bin 拷贝到分发目录。
tos.py idf <idf.py 子命令> [--idf-flags=...]tos.py idf menuconfig
tos.py idf fullclean仅 ESP32。对 ESP32 平台执行 idf.py 命令,需选用 ESP32 配置。
全局参数
以下参数对所有子命令生效:
-d/--debug—— 显示调试级执行日志(如tos.py -d version)。-h/--help—— 显示命令帮助(如tos.py flash -h)。