Repository navigation
Format the Python tools with Ruff, plus a report-only format check - #434
Conversation
1b0d759 to
f3d2d88
Compare
jiangkoumo
left a comment
There was a problem hiding this comment.
在本地复现过,结论:可以合并。
复现(Debian 13 x86_64,node 22.23.3):
• 在 52dd148 上跑 npx @biomejs/biome@2.5.15 format --write .(dsh 下两遍,第一遍 183 个、第二遍 2 个),再跑 ruff 0.17.2 format(32 个),结果和 f3d2d88 只差一个文件:dsh/sim/avatars/build.py。
• 差别:f3d2d88ca 里 VARIANT_POSES 和 ELLEN_POSES 两个列表拆成了每行一项(看起来是按默认 88 宽格式化的),按 ruff.toml 的 120 宽重跑会保留在一行。因为有尾逗号,64fcd0631 上 ruff format --diff 仍然判定已格式化,不影响新的 CI 检查,只是和 PR 里“结果应完全等于 commit 2”的说法差这一处。顺手重新生成一下就能对齐。
• 64fcd06 上 biome format 和 ruff format --diff 都干净;32 个 Python 文件格式化前后 AST 全部相同。
测试(base 8e2fce2 对比 head 64fcd06,结果完全一致):
• dsh npm test:两边都是 16/17,失败的那项是 REBUILD.md §4 在我的 worktree 里找不到 core/docs/issues/352/fixes,属于环境问题,和这个 PR 无关。
• core/tools 和 tools 下 9 个 Python 测试文件:两边都是 8 个 OK,test_ci_tests 两边都因离线 cargo metadata 失败。
关于 #427:它是长期 Draft,不用等它,这个 PR 先合就行。我试合并过,#427 会有 8 个文件冲突(check_product_boundary.py、它的测试,以及 dsh/packages/host/src 下 6 个文件),我们同步 main 时用同版本 biome/ruff 重新格式化即可解决。
另外同意加 .git-blame-ignore-revs 收录格式化那个提交。
…n tools ruff.toml formats the maintained Python tools (core/tools, tools): Python 3.11 (tomllib), width 120. Docs, evidence and core/vendor are outside its include list. It pins Ruff 0.17.2 and gives the command. .github/workflows/format.yml runs `ruff format --diff` when those files or the config change: one job of about fifteen seconds. Like ci.yml it reports and never gates: it is not a required check and nothing runs before a push. Lint findings are not checked. AGENTS.md §4 names the config and the lane. Production LOC: 102160 -> 102160 (delta 0) core 96788 -> 96788, api 5372 -> 5372; reference absent (retired R9c; last counted 65,417 at tree 498dd19). Method: python3 -B tools/production_loc.py (parent's copy) --root on git archive of the parent (4497b0c) and the commit tree.
One mechanical pass with the previous commit's config, no hand edits: `ruff format` at the root. 31 files in core/tools and tools change; a second run changes nothing. Lint findings are not fixed here. Checked: `ruff format --check` is clean, and each changed file parses to the same AST as before (docstring indentation aside). Tests were not run. Production LOC: 102160 -> 102160 (delta 0) core 96788 -> 96788, api 5372 -> 5372; reference absent (retired R9c; last counted 65,417 at tree 498dd19). Development tools are outside every counted scope. Method: as in the previous commit.
64fcd06 to
69d9cdc
Compare
…ral-AI-Lab#440) into feat/macos-native-on-main Conflicts in core/tools/check_product_boundary.py and its test: kept this branch's changes and reformatted with ruff 0.17.2 (upstream side was format-only; AST of the result equals this branch's version).
Why
Rust has rustfmt in CI. The Python tools in
core/toolsandtoolshave no formatter, even though CI and agents rely on them: CI test selection, guards, cleanup, worktrees and the production LOC counter. Each author's and each agent's style landed as written, which costs something in review:git blamepoint at more than what changed.With one pinned formatter, a diff shows only the change, and style is settled by a single command.
Why it is safe
pipx run --spec ruff==0.17.2 ruff format. The result should be commit 2 exactly.core/toolsandtoolsonly. Docs, evidence trees andcore/vendor/are untouched.What is in it
ruff.toml: Python 3.11 (the code usestomllib), width 120..github/workflows/format.yml: runsruff format --diff. It does not check lint findings, so it starts green.Notes
main. This PR now covers only the Python tools. The JavaScript/TypeScript part moved withdsh/and is now Ephemeral-AI-Lab/dsh-layerfs#2.ci.ymlruns thecore/toolsunit tests on this PR.