Add pre-commit including config and GitHub workflow#563
Add pre-commit including config and GitHub workflow#563m1yag1 merged 2 commits intopyslackers:mainfrom
Conversation
Quidge
left a comment
There was a problem hiding this comment.
Some notes but +1 on this add (and how you've added it)!
| - uses: actions/setup-python@v6 | ||
| with: | ||
| python-version: "3.12" | ||
| - uses: pre-commit/action@v3.0.1 |
There was a problem hiding this comment.
I've rolled without using the dedicated pre-commit action before, but something I've added in my own CI is the --show-diff-on-failure flag. It will show a git diff on a failure so you can see the issue in the CI readout. Unsure if the dedicated pre-commit CI action is already doing that under the hood (should be easy enough to check source for that action and confirm if they're using it or not; they likely also have a way to pass arbitrary flags).
There was a problem hiding this comment.
It does use -show-diff-on-failure: https://github.com/pre-commit/action/blob/main/action.yml#L19
| - id: ruff-check | ||
| args: [--exit-non-zero-on-fix] | ||
| - id: ruff-format | ||
| args: [--exit-non-zero-on-fix] |
There was a problem hiding this comment.
Isn't exit-non-zero the default? And/or, when pre-commit runs, if a delta is detected, doesn't the delta itself cause pre-commit to trip a failure anyways?
There was a problem hiding this comment.
Yes. But Ruff can also auto-magically fix some formatting and linting issues. In which case, it exits with a zero status code from what I've seen. We don't have the fix attribute set so it won't auto-fix any issues currently but I'd still suggest we leave this argument on, in case fix is enabled in the future.

Relevant Issue & Description
https://pythondev.slack.com/archives/C2FMLUBEU/p1757474340679269
This PR introduces pre-commit to automatically enforce code formatting and linting standards across the project, especially related to Ruff.
Pre-commit Setup
Enforced linting and formatting via GitHub Workflow
Project Configuration Updates
File Formatting
Screenshots, if applicable