ruff: format + lint as a first-class gate#123
Merged
Merged
Conversation
Lands the ruff half of the Python toolchain (plan \xc2\xa7B2). Config: [tool.ruff] in //:pyproject.toml \xe2\x80\x94 line-length 100, target py314, src = [meta, tools], select E/F/I/B/UP/SIM/RUF/S. Per-file ignores carve out S603/S607 for meta/scripts (subprocess calls to first-party tools by name) and S101/S105/S106/S108/S311 for tests. Where ruff runs: - Pre-commit: ruff-check --fix then ruff-format (fix order matters; check re-sorts imports, format finishes). - CI: new `ruff` job mirrors golangci-lint\xe2\x80\x99s shape, uses astral-sh/ruff-action with version pinned alongside the Dockerfile ARG. Added to build-and-test-per-target.needs to gate merge. - Devcontainer: installed via uv tool install during image build. UV_TOOL_DIR is forced to /usr/local/share/uv-tools so the root-owned install is reachable by the vscode user. - VS Code: charliermarsh.ruff in extensions.json + devcontainer.json; settings.json sets ruff as the default Python formatter with source.fixAll.ruff + source.organizeImports.ruff as save-time actions. Renovate: new regex matcher for .github/workflows/*.yml picks up the `version:` input under `# renovate: ...` (mirrors the Dockerfile pattern), and a ruff packageRule groups both pins into one PR. Existing meta/scripts/*.py reformatted by `ruff format` and the four real findings fixed (SIM102 nested-if, two E501 long error messages, SIM115 NamedTemporaryFile-without-with). Test files\xe2\x80\x99 RUF005 fixed inline. README: new ruff row in the CI checks table, ruff-check / ruff-format / uv-lock-fresh rows in the pre-commit table, charliermarsh.ruff in the recommended extensions, and a `ruff (diagnostics + format)` row in the on-save table.
MODULE.bazel pins rules_python to 3.14 and pyproject.toml targets py314. Ubuntu-24.04 runners still ship 3.12 as `python3`, so the CI sites that invoke a script outside Bazel run on the wrong interpreter. Ruff 0.15.17, correctly honouring target-version=py314, applies the PEP 758 transform `except (A, B, C):` -> `except A, B, C:` to _workspace.py; that\xe2\x80\x99s valid 3.14 syntax but a SyntaxError on 3.12, which is what tanked the four go-* / no-cgo checks on PR 123\xe2\x80\x99s last run. Adds `actions/setup-python@v5` with `python-version: "3.14"` to the five sites that call `python3 meta/scripts/...`. The renovate workflow-yaml matcher is widened to accept `python-version:` alongside `version:` so the new pins are tracked and grouped with the MODULE.bazel python_version under "Language toolchain SDKs".
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #123 +/- ##
==========================================
+ Coverage 86.31% 86.35% +0.04%
==========================================
Files 35 35
Lines 1841 1840 -1
Branches 51 50 -1
==========================================
Hits 1589 1589
Misses 241 241
+ Partials 11 10 -1
Continue to review full report in Codecov by Harness.
🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Lands the ruff half of the Python toolchain (plan §B2). With this PR,
ruff format --checkandruff checkare gating on every PR, the matching fixes run as pre-commit hooks in the devcontainer, and VS Code surfaces ruff diagnostics + format-on-save inline.Config — one canonical home
[tool.ruff]in//:pyproject.toml:line-length = 100,target-version = "py314",src = ["meta", "tools"]E F I B UP SIM RUF S(pycodestyle/pyflakes baseline, imports, bugbear, pyupgrade, simplify, ruff's own, bandit)meta/scripts/**→S603,S607— these scripts shell out togit/goby name through a controlled PATH; the rules are noise here.**/test_*.py,**/*_test.py→S101 S105 S106 S108 S311—assertin tests, throwaway fixture "secrets", non-crypto randomness, and stable fake-path mock arguments are not real findings.Where ruff runs
ruff check --fixthenruff format(check first so import sorting settles before format)ruffjob, modeled ongolangci-lint's shape;astral-sh/ruff-action@v4.0.0pinned by SHA,version: "0.15.17"pinned alongside the Dockerfile ARG. Added tobuild-and-test-per-target.needsto gate merge.uv tool installduring image build.UV_TOOL_DIR=/usr/local/share/uv-toolsso the root-owned install is reachable by thevscodeuser — the default~/.local/share/uvwould land in/root(mode 700) and break the/usr/local/bin/ruffsymlink.charliermarsh.ruffinextensions.json+devcontainer.json;settings.jsonmakes ruff the default Python formatter withsource.fixAll.ruff+source.organizeImports.ruffas save-time code actions.Renovate
New regex matcher for
.github/workflows/*.ymlpicks up the# renovate: …comment aboveversion: "<pin>"(same shape as the Dockerfile ARG pattern). AruffpackageRule groups both the Dockerfile ARG and the workflow version pin into a single PR so they bump together.Existing meta/scripts/*.py cleanup (in scope)
CI would break between PRs without this, so the cleanup folds in:
ruff format— mechanical, zero behavior change.SIM102(nested if collapsed), 2×E501(long error messages wrapped via f-string continuation),SIM115(tempfile.NamedTemporaryFilewrapped inwith),RUF005([…] + files→[…, *files]in a test).README
New rows in the CI checks table (
ruff), the pre-commit hook table (ruff-check,ruff-format, plus theuv-lock-freshrow missed in PR #121), and the editor on-save table (rufffor diagnostics + format).charliermarsh.ruffadded to the recommended-extensions list with a one-line rationale.Test plan
ruff format --check .clean in devcontainerruff check .clean in devcontainer (no remaining findings)bazel test //...11/11 passpre-commit run --all-filescleanwhich ruffreturns/usr/local/bin/ruffandruff --versionreports 0.15.17 as thevscodeuser