Skip to content

Format the Python tools with Ruff, plus a report-only format check - #434

Merged
yifanxuaaa merged 2 commits into
Ephemeral-AI-Lab:mainfrom
FogMoe:style/biome-ruff-format
Oct 24, 2026
Merged

yifanxuaaa merged 2 commits into
Ephemeral-AI-Lab:mainfrom
FogMoe:style/biome-ruff-format

Conversation

@scarletkc

@scarletkc scarletkc commented Oct 23, 2026 •

Copy link
Copy Markdown
Contributor

Why

Rust has rustfmt in CI. The Python tools in core/tools and tools have 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:

  • Diffs hide the real change. A fix in a long, dense line rewrites the whole line, so reviewers and git blame point at more than what changed.
  • Parallel branches conflict on lines nobody meant to touch. This repository runs many worktrees and agents at once.
  • Style keeps coming back up. Without a config, each contributor has to guess the house style.

With one pinned formatter, a diff shows only the change, and style is settled by a single command.

Why it is safe

  • No behavior change.
    • Every changed file parses to the same AST as before. Docstring indentation is the only allowed difference.
    • Production LOC is unchanged at 102160, because development tools are outside every counted scope.
  • Reproducible. Check out commit 1 and run pipx run --spec ruff==0.17.2 ruff format. The result should be commit 2 exactly.
  • Follows AGENTS.md §4. The check only reports: it is not a required check, nothing runs before a push, and there is no hook.
  • Narrow scope. It touches core/tools and tools only. Docs, evidence trees and core/vendor/ are untouched.
  • Cheap CI. One job of about 15 seconds, which runs only when those files or the config change.

What is in it

  1. Config and check (cc1d509d)
    • ruff.toml: Python 3.11 (the code uses tomllib), width 120.
    • .github/workflows/format.yml: runs ruff format --diff. It does not check lint findings, so it starts green.
    • Two short additions to AGENTS.md §4.
  2. One format pass (69d9cdc): 31 files, all generated by Ruff, with no hand edits.

Notes

  • Rebuilt on current main. This PR now covers only the Python tools. The JavaScript/TypeScript part moved with dsh/ and is now Ephemeral-AI-Lab/dsh-layerfs#2.
  • Not run: tests were not run locally. The existing ci.yml runs the core/tools unit tests on this PR.
  • Reviewing: read commit 1, and check commit 2 by regenerating it.

@scarletkc
scarletkc force-pushed the style/biome-ruff-format branch from 1b0d759 to f3d2d88 Compare October 23, 2026 10:12
@scarletkc scarletkc changed the title style: add Biome and Ruff configs and format dsh JS/TS and the Python tools Format dsh JS/TS and the Python tools with Biome and Ruff, plus a report-only format check Oct 23, 2026

@jiangkoumo jiangkoumo left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

在本地复现过,结论:可以合并。

复现(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.
@scarletkc
scarletkc force-pushed the style/biome-ruff-format branch from 64fcd06 to 69d9cdc Compare October 24, 2026 01:05
@scarletkc scarletkc changed the title Format dsh JS/TS and the Python tools with Biome and Ruff, plus a report-only format check Format the Python tools with Ruff, plus a report-only format check Oct 24, 2026
@yifanxuaaa
yifanxuaaa merged commit c77281e into Ephemeral-AI-Lab:main Oct 24, 2026
4 checks passed
jiangkoumo added a commit to jiangkoumo/layerfs that referenced this pull request Oct 24, 2026
…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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants