Skip to content

Replace black/flake8/isort with ruff for lint + format - #67

Merged
stefanbschneider merged 2 commits into
mainfrom
ruff-tooling
Aug 12, 2026
Merged

stefanbschneider merged 2 commits into
mainfrom
ruff-tooling

Conversation

@stefanbschneider

@stefanbschneider stefanbschneider commented Aug 12, 2026 •

Copy link
Copy Markdown
Owner

Summary

  • Replace black, flake8, and isort with ruff for both linting and formatting.
  • ruff.toml: line-length = 100 (matches the previous flake8 setting), select = ["E", "F", "W", "I"] (I replaces isort), and a per-file F401 ignore for __init__.py (previously only passed on the CI flake8 command line via --per-file-ignores, so pre-commit never actually enforced it). *.ipynb and *.md are excluded from ruff format — black never touched notebooks, and ruff's markdown support would otherwise reformat the Python code fences embedded in the docs, which is out of scope here.
  • Delete setup.cfg (it only held the flake8 config).
  • .pre-commit-config.yaml: drop the black/flake8/isort hooks, add astral-sh/ruff-pre-commit (ruff-check --fix, ruff-format); also bumped the stale pre-commit-hooks pin (v2.3.0 → v6.0.0) while touching this file.
  • CI (.github/workflows/python-package.yml): replace the "Lint with flake8" step with ruff check ., and add a new ruff format --check . step. This is a real behavior change, not just a swap — CI previously never checked formatting at all; black/isort only ran locally via pre-commit.
  • tests/requirements.txt: flake8 → ruff.
  • Reformatted all Python sources with ruff format (mostly re-wrapping lines that black had wrapped at 88 chars, now allowed up to 100 to match the lint config) and ran ruff check --fix (clean — no violations beyond formatting).

README badges

  • Swapped the "Code Style: Black" badge for the official Ruff badge.
  • Removed the "PyPI" badge — it was actually the python-publish.yml workflow-status badge, which only runs on release tags, so it reads stale/broken most of the time. Replaced with a real PyPI version badge linking to the package's PyPI page.
  • Added a License (MIT) badge, since none existed despite the project being MIT-licensed.
  • Pointed the Colab links at main instead of master — the repo has no master branch, so those only ever worked via GitHub's redirect.

Dependency updates

Beyond the ruff swap itself: pre-commit-hooks v2.3.0 → v6.0.0. I checked uv pip list --outdated; core runtime deps (gymnasium, numpy, pandas, matplotlib, pygame, shapely) were already bumped and verified in the immediately preceding commit (b07257b), and nothing there is newly outdated except transitive CUDA/nvidia/pydantic-core pins and gymnasium 1.2.2 (pinned exactly by ray[rllib], already inside setup.py's >=0.29.1,<2.0 range) — so those were left alone.

Not included: the stuck-CI ruleset issue

Separately reported (and diagnosed, but not fixed here — it's a repo Settings change, not a code change): the main branch ruleset requires status check build (ubuntu-latest, 3.9), but the CI matrix hasn't run 3.9 since an earlier commit (now 3.10–3.13). That context can never be reported, so every PR — including this one — sits "Expected — Waiting for status to be reported" forever. Fix is to update the ruleset's required checks to swap 3.9 for 3.13 (Settings → Rules → Rulesets → main).

Verification

  • pytest — 11 passed
  • pytest --nbmake examples/test.ipynb — 1 passed
  • pre-commit run --all-files — clean
  • ruff check . / ruff format --check . — clean
  • Sanity-checked the ruff config actually enforces line length and import order (not just defaults) by injecting a >100-char line and unsorted imports into scratch copies and confirming ruff check flags them (E501, I001) before relying on it.

🤖 Generated with Claude Code

- Add ruff.toml: line-length 100 (matches the old flake8 setting), select
  E/F/W/I (I replaces isort), and a per-file F401 ignore for __init__.py
  (previously only passed on the CI flake8 command line, so pre-commit never
  enforced it). Exclude *.ipynb and *.md from `ruff format` -- black never
  touched notebooks, and ruff's markdown support reformats embedded Python
  code fences in the docs, which is out of scope here.
- Delete setup.cfg (only held the flake8 config).
- .pre-commit-config.yaml: drop black/flake8/isort hooks, add
  astral-sh/ruff-pre-commit (ruff-check --fix, ruff-format); bump the stale
  pre-commit-hooks pin (v2.3.0 -> v6.0.0).
- CI: replace the flake8 lint step with `ruff check .`, and add a new
  `ruff format --check .` step -- CI previously never checked formatting at
  all (black/isort only ran via pre-commit).
- tests/requirements.txt: flake8 -> ruff.
- Reformat all Python sources with `ruff format` (mostly re-wrapping lines
  that black had wrapped at 88 chars, now allowed up to 100) and apply
  `ruff check --fix` (clean; no violations beyond formatting).
- README: swap the "Code Style: Black" badge for the official Ruff badge;
  also point the Colab links at `main` instead of `master` (the repo has no
  master branch -- these only worked via GitHub's redirect).
- CLAUDE.md: update the Commands/gotcha text that referenced flake8, black,
  isort, and setup.cfg; also correct a stale "Python >= 3.9" note that no
  longer matched setup.py/CI (>=3.10).

Dependency updates beyond the ruff swap itself: pre-commit-hooks v2.3.0 ->
v6.0.0. Core runtime deps (gymnasium, numpy, pandas, matplotlib, pygame,
shapely) were already bumped and verified in the immediately preceding
commit (b07257b); nothing there is newly outdated except transitive
CUDA/nvidia/pydantic-core pins and gymnasium 1.2.2 (pinned by ray[rllib],
already inside setup.py's >=0.29.1,<2.0 range), so those were left alone.

Verified: pytest (11 passed), pytest --nbmake examples/test.ipynb (1
passed), and pre-commit run --all-files (clean) all pass locally.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X4RPjRuz4qpmA9XFRkKKRM
Copilot AI lite review requested due to automatic review settings August 12, 2026 11:42

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The old "PyPI" badge was actually the python-publish.yml workflow-status
badge, which only runs on release tags, so it reads as stale/broken most of
the time. Replace it with the actual PyPI version badge (links to the
package's PyPI page instead of a CI workflow run). Also add a License badge
since none existed despite the project being MIT-licensed.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01X4RPjRuz4qpmA9XFRkKKRM
@stefanbschneider
stefanbschneider merged commit 9a137bc into main Aug 12, 2026
12 checks passed
@stefanbschneider
stefanbschneider deleted the ruff-tooling branch August 12, 2026 13:26
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.

2 participants