|
| 1 | +# Migrate from black + pycodestyle to ruff |
| 2 | + |
| 3 | +## Context |
| 4 | +The project currently uses **black** (formatter) and **pycodestyle** (linter) as separate tools. Ruff is a faster, unified replacement that handles both formatting and linting. This migration consolidates two tools into one, with faster execution and a single configuration surface. |
| 5 | + |
| 6 | +## Changes |
| 7 | + |
| 8 | +### 1. Update `pyproject.toml` dependencies |
| 9 | +- **Remove** `black >= 22.8.0` and `pycodestyle >= 2.9.1` from `[dependency-groups] dev` |
| 10 | +- **Add** `ruff >= 0.9.0` to `[dependency-groups] dev` |
| 11 | + |
| 12 | +### 2. Add ruff configuration to `pyproject.toml` |
| 13 | +Add the following sections: |
| 14 | +```toml |
| 15 | +[tool.ruff] |
| 16 | +line-length = 88 # match black's default |
| 17 | +target-version = "py310" |
| 18 | + |
| 19 | +[tool.ruff.lint] |
| 20 | +select = ["E", "W", "F"] # pycodestyle errors/warnings + pyflakes |
| 21 | +``` |
| 22 | + |
| 23 | +### 3. Update CI workflow — `.github/workflows/lint.yml` |
| 24 | +Replace: |
| 25 | +```yaml |
| 26 | +- name: Check formatting |
| 27 | + run: uv run black --check bcb/ tests/ |
| 28 | +``` |
| 29 | +With: |
| 30 | +```yaml |
| 31 | +- name: Check formatting |
| 32 | + run: uv run ruff format --check bcb/ tests/ |
| 33 | +- name: Lint |
| 34 | + run: uv run ruff check bcb/ tests/ |
| 35 | +``` |
| 36 | +
|
| 37 | +### 4. Update `CLAUDE.md` |
| 38 | +Replace the linting/formatting commands: |
| 39 | +```bash |
| 40 | +uv run ruff check bcb/ # lint with ruff |
| 41 | +uv run ruff format bcb/ # format with ruff |
| 42 | +``` |
| 43 | + |
| 44 | +### 5. Run `ruff format` on the codebase |
| 45 | +Run `uv run ruff format bcb/ tests/` to reformat with ruff (should produce no changes since ruff format is black-compatible by default, but verify). |
| 46 | + |
| 47 | +### 6. Run `uv sync` to update lockfile |
| 48 | +After dependency changes, run `uv sync` to regenerate `uv.lock`. |
| 49 | + |
| 50 | +## Files to modify |
| 51 | +- `pyproject.toml` — deps + ruff config |
| 52 | +- `.github/workflows/lint.yml` — CI steps |
| 53 | +- `CLAUDE.md` — documented commands |
| 54 | + |
| 55 | +## Verification |
| 56 | +1. `uv run ruff format --check bcb/ tests/` — passes with no changes |
| 57 | +2. `uv run ruff check bcb/ tests/` — no lint errors |
| 58 | +3. `uv run mypy bcb/` — still passes (unchanged) |
| 59 | +4. `uv run pytest -m "not integration"` — all tests pass |
0 commit comments