Skip to content

Commit a765274

Browse files
authored
Merge pull request #3 from LanternCX/dev
v1.0.1
2 parents 05d0bf4 + f42ef81 commit a765274

20 files changed

Lines changed: 1192 additions & 40 deletions

.progress/PROGRESS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,4 @@ abc123d (or TBD)
3939
| Page ID | Date | Title | Path | Keywords |
4040
| --- | --- | --- | --- | --- |
4141
| 2026-03-03-1 | 2026-03-03 | Stabilized full deploy flow and improved onboarding UX | `.progress/entries/2026/2026-03-03-1.md` | deploy, mpremote, config-wizard, docs |
42+
| 2026-03-04-1 | 2026-03-04 | Added configurable device upload directory with scoped full wipe | `.progress/entries/2026/2026-03-04-1.md` | sync, device-upload-dir, full-mode, planner, mpremote |
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# 2026-03-04-1
2+
3+
## Date
4+
2026-03-04
5+
6+
## Title
7+
Added configurable device upload directory with scoped full wipe
8+
9+
## Background / Issue
10+
Users needed to deploy files into a specific directory on the target MicroPython device instead of always syncing to the device root. The existing full-sync wipe behavior also cleared the whole filesystem root, which was too broad once per-project upload directories are introduced.
11+
12+
## Actions / Outcome
13+
- Approach 1: Added `device_upload_dir` to config defaults, parser, saver, and interactive wizard -> users can persist upload target directory via `init/config` without manual TOML edits.
14+
- Approach 2: Extended planner to accept `remote_base_dir` and prefix upload/delete remote paths while setting full-mode wipe target to that directory -> deployment operations are now scoped to configured destination.
15+
- Approach 3: Extended backend and executor to pass wipe target directory through to `mpremote` cleanup script, including path normalization and `/flash` compatibility handling -> full-mode cleanup no longer requires wiping device root when a target directory is configured.
16+
- Approach 4: Updated README and expanded regression tests across config/cli/planner/executor/backend/docs checks -> behavior is documented and protected by automated coverage.
17+
- Final approach: Combined config + planning + execution + docs + tests in one change set -> enabled directory-scoped uploads and safer full-sync semantics.
18+
19+
## Lessons / Refinements
20+
- Scope-sensitive deployment behavior should be modeled in plan objects first, then propagated into execution to keep logic auditable and testable.
21+
- For embedded targets, destructive operations must default to least-surprise scope (target directory) when user intent is explicit.
22+
23+
## Related Commit Message
24+
feat(sync): support configurable device upload directory
25+
26+
## Related Commit Hash
27+
TBD

README.md

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515

1616
如果你是第一次使用本项目,可以遵循以下步骤。
1717

18+
阅读完本章之后,建议继续阅读 [在其他项目中安装为命令行工具](#install)
19+
1820
### 0) 环境要求
1921

2022
- Python 版本:`>= 3.10`(推荐 `3.11`
@@ -71,6 +73,8 @@ mpy-cli init
7173

7274
`init` 会进入交互式配置向导(可扫描设备端口并选择),无需手动编辑配置文件。
7375

76+
`plan/deploy` 交互模式下,如果未提供 `--port`,会自动扫描可用端口并提示选择。
77+
7478
初始化后会生成:
7579

7680
- `.mpy-cli.toml`
@@ -81,7 +85,7 @@ mpy-cli init
8185

8286
### 6) 后续重配(可选)
8387

84-
如果你后续想修改端口、同步模式、运行目录等配置,直接执行:
88+
如果你后续想修改端口、同步模式、运行目录、设备上传目录等配置,直接执行:
8589

8690
```bash
8791
mpy-cli config
@@ -117,6 +121,7 @@ mpy-cli deploy --no-interactive --yes
117121

118122
---
119123

124+
<span id="install"></span>
120125
## 在其他项目中安装为命令行工具
121126

122127
如果你要把 `mpy-cli` 安装到另一个项目里使用,推荐在该项目自己的虚拟环境中安装:
@@ -141,6 +146,7 @@ mpy-cli init
141146
mpy-cli config
142147
mpy-cli plan
143148
mpy-cli deploy
149+
mpy-cli upload
144150
```
145151

146152
说明:
@@ -177,6 +183,12 @@ mpy-cli config
177183
- 无额外参数。
178184
- 进入交互式配置向导,更新 `.mpy-cli.toml`
179185

186+
常用配置项说明:
187+
188+
- `device_upload_dir`:设备端上传目录前缀,留空表示设备根目录。
189+
-`device_upload_dir = "apps/demo"` 时,本地 `main.py` 会上传到设备 `:apps/demo/main.py`
190+
- `full` 模式会清空该上传目录,而不是整机设备根目录。
191+
180192
### `mpy-cli plan`
181193

182194
```bash
@@ -199,6 +211,34 @@ mpy-cli deploy [--mode {incremental,full}] [--port PORT] [--no-interactive] [--y
199211
- `--no-interactive`:禁用交互提问。
200212
- `--yes`:跳过执行前确认(包括全量模式二次确认)。
201213

214+
推荐用法:
215+
216+
```bash
217+
mpy-cli deploy --no-interactive --yes
218+
```
219+
220+
进行 `config` 之后直接无交互烧入
221+
222+
### `mpy-cli upload`
223+
224+
```bash
225+
mpy-cli upload [--local LOCAL] [--remote REMOTE] [--port PORT] [--no-interactive] [--yes]
226+
```
227+
228+
- `--local`:本地文件路径(如 `seekfree_demo/E01_demo.py`)。
229+
- `--remote`:设备目标路径;不传时交互模式默认与本地路径一致,可手动修改。
230+
- `--port`:指定设备端口。
231+
- `--no-interactive`:禁用交互提问;此时需显式提供 `--local``--remote`
232+
- `--yes`:跳过执行前确认。
233+
234+
推荐用法:
235+
236+
```bash
237+
mpy-cli upload --local <LOCAL>
238+
```
239+
240+
填写字段 `LOCAL` 指定本地文件路径之后交互式确认远程路径
241+
202242
---
203243

204244
## 常见问题
@@ -236,4 +276,4 @@ python3 -m pip install mpremote
236276

237277
本仓库采用 GPL-3.0 协议开源,如果用于竞赛目的可酌情在赛后遵守协议。
238278

239-
欢迎 Issue / PR / Star。
279+
欢迎 Issue / PR / Star。
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# 手动单文件上传功能设计文档
2+
3+
## 背景
4+
5+
当前 `mpy-cli` 仅支持 `plan/deploy` 的计划式同步流程。对于临时上传单个脚本文件(例如 `seekfree_demo/E01_demo.py`)的场景,用户需要依赖 Git 变更或全量同步,成本较高。
6+
7+
本设计新增独立 `upload` 命令,支持手动输入本地文件路径,并在交互中确认/修改设备目标路径。
8+
9+
## 目标
10+
11+
- 新增 `mpy-cli upload` 子命令,用于单文件上传。
12+
- 交互模式下仅通过手动输入本地文件路径,不做文件列表扫描。
13+
- 目标路径默认与本地输入路径一致(如 `demo/demo.py` -> 默认目标 `demo/demo.py`),允许手动修改。
14+
- 执行前显示上传预览并二次确认。
15+
- 复用现有执行链(`DeployExecutor` + `MpremoteBackend`),保持日志与错误行为一致。
16+
17+
## 非目标
18+
19+
- 不改变 `plan/deploy` 的现有语义与流程。
20+
- 不在本次支持多文件批量上传。
21+
- 不新增额外运行时持久化文件。
22+
23+
## 交互与参数设计
24+
25+
### 命令形态
26+
27+
```bash
28+
mpy-cli upload [--local LOCAL] [--remote REMOTE] [--port PORT] [--no-interactive] [--yes]
29+
```
30+
31+
### 参数含义
32+
33+
- `--local`:本地文件路径。
34+
- `--remote`:设备相对目标路径。
35+
- `--port`:设备端口。
36+
- `--no-interactive`:禁用交互提问;缺参数时直接报错。
37+
- `--yes`:跳过执行前确认。
38+
39+
### 交互流程(无对应参数时)
40+
41+
1. 解析端口(沿用现有优先级:`--port` > 配置 > 扫描/手输)。
42+
2. 提示输入本地文件路径。
43+
3. 以本地输入路径作为默认值,提示输入设备目标路径(可直接回车)。
44+
4. 打印预览:端口、本地路径、最终设备路径。
45+
5. 确认后执行上传。
46+
47+
## 路径与执行语义
48+
49+
- `--remote` 或交互输入的目标路径统一作为“设备相对路径”。
50+
- 最终远端路径由 `device_upload_dir + remote_path` 拼接得到,与现有 `deploy` 规则一致。
51+
- 例:
52+
- `device_upload_dir = ""``remote = "seekfree_demo/E01_demo.py"` -> `:seekfree_demo/E01_demo.py`
53+
- `device_upload_dir = "apps/demo"``remote = "seekfree_demo/E01_demo.py"` -> `:apps/demo/seekfree_demo/E01_demo.py`
54+
55+
## 校验与错误处理
56+
57+
- 本地路径必须存在且为普通文件,否则提示并返回失败码。
58+
- 目标路径去空白后不能为空。
59+
- 非交互模式下缺失 `--local``--remote``--port`(且配置无法补足)时直接报错。
60+
- 保持 `mpremote` 不可用与执行失败的现有报错风格。
61+
62+
## 实现边界
63+
64+
- `mpy_cli/cli.py`:新增 `upload` 命令解析和 `_cmd_upload` 流程。
65+
- `mpy_cli/planner.py`:仅复用 `PlanOperation/DeployPlan` 数据结构,不新增新操作类型。
66+
- `mpy_cli/executor.py`:无需改动核心逻辑,复用既有 `upload` 分支执行。
67+
68+
## 测试策略(TDD)
69+
70+
- `tests/test_cli.py`
71+
- `upload` 在交互模式下可读取本地路径并生成默认远端路径。
72+
- `upload` 可接受手动修改后的远端路径。
73+
- 非交互模式缺失必要参数时报错。
74+
- 本地路径不存在时报错。
75+
- `tests/test_docs_and_ci.py`
76+
- README 参数总览新增 `mpy-cli upload` 与相关参数。
77+
78+
## 验收标准
79+
80+
- 用户可通过 `mpy-cli upload` 独立上传单文件。
81+
- 用户输入 `seekfree_demo/E01_demo.py` 后,远端默认同路径并可改写。
82+
- 上传前有清晰预览与确认(`--yes` 可跳过)。
83+
- 新增测试通过且不破坏现有 `plan/deploy` 流程。

0 commit comments

Comments
 (0)