chore: add Ruff pre-commit checks#729
Conversation
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: ad0276fdac
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| name: ruff format (check) | ||
| entry: ruff format --check | ||
| language: system | ||
| types_or: [python] |
There was a problem hiding this comment.
Include notebooks in Ruff hook file filters
The new local Ruff hooks are restricted to types_or: [python], which means pre-commit will not pass .ipynb files to either ruff format --check or ruff check. This is a regression from the previous ruff ... . commands in format-check, which did include notebooks (Ruff currently discovers examples/notebooks/*.ipynb by default). As a result, notebook code can now bypass lint/format checks in both pre-commit run --all-files and make format-check.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
Pull request overview
This PR integrates the repository’s existing Ruff formatting/linting checks into pre-commit, updates make format-check to delegate to pre-commit, and refreshes contributor documentation to reflect the new workflow.
Changes:
- Updated
make format-checkto runpre-commit run --all-filesinstead of invoking Ruff directly. - Added local pre-commit hooks for
ruff format --checkandruff check. - Updated
CONTRIBUTING.mdto recommend running pre-commit-based checks before committing.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
Makefile |
Switches format-check to run pre-commit hooks (instead of direct Ruff commands). |
CONTRIBUTING.md |
Updates the recommended local workflow to include pre-commit. |
.pre-commit-config.yaml |
Adds Ruff check hooks to pre-commit (local/system hooks). |
Comments suppressed due to low confidence (2)
.pre-commit-config.yaml:30
language: systemfor this Ruff hook makes the pre-commit run depend on whateverruffis available on the user's PATH at commit time (e.g., it can fail when the virtualenv isn’t activated, and it doesn’t pin a Ruff version). Consider using the officialastral-sh/ruff-pre-commitrepo (pinnedrev) or a non-system hook setup so pre-commit manages the Ruff environment consistently.
- id: ruff-check
name: ruff check
entry: ruff check
language: system
types_or: [python]
.pre-commit-config.yaml:31
- With
types_or: [python], this hook will not run on Jupyter notebooks (.ipynb). Previouslyruff format --check ./ruff check .(inmake format-check) would also cover notebooks underexamples/notebooks, so this is a behavior change and may miss issues there. Consider expanding the hook to include.ipynbfiles (e.g., via an appropriatetypes/filesmatcher).
entry: ruff check
language: system
types_or: [python]
description: "Run Ruff lint checks."
| - repo: local | ||
| hooks: | ||
| - id: ruff-format-check | ||
| name: ruff format (check) | ||
| entry: ruff format --check | ||
| language: system | ||
| types_or: [python] | ||
| description: "Ensure Python files are formatted with Ruff." | ||
| - id: ruff-check | ||
| name: ruff check | ||
| entry: ruff check | ||
| language: system |
| entry: ruff format --check | ||
| language: system | ||
| types_or: [python] | ||
| description: "Ensure Python files are formatted with Ruff." |
| Before committing code, make sure the checks pass. The common file-level checks are | ||
| handled by pre-commit, which `make install-dev` installs for you: | ||
|
|
||
| ``` | ||
| pre-commit run --all-files | ||
| make format | ||
| make static-checks | ||
| ``` |
What has changed and why?
Added the existing Ruff checks to pre-commit so contributors can run the same Python
checks locally with one command.
Updated
make format-checkto use pre-commit and refreshedCONTRIBUTING.mdto pointto the new workflow.
How has it been tested?
pre-commit run --all-filesmake format-checkruff-format-checkfailed on bad formatting, passed after fixingruff-checkfailed on lint errors, passed after fixingDid you update CHANGELOG.md?
Did you update the documentation?