Implement pre-commit hooks: black and isort#368
Open
annalena-k wants to merge 8 commits into
Open
Conversation
vincentberenz
approved these changes
Mar 23, 2026
vincentberenz
left a comment
Collaborator
There was a problem hiding this comment.
Great to streamline formatting !
I added a minor comment
|
I think it would be a good idea to use Ruff instead, since it combines Black and isort I already did this in my fork, and it also includes the merge with main. So if you think Fork: https://github.com/ewencedr/dingo/tree/ruff-pre-commit |
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.
This PR implements automatic formatting via
blackand import sorting viaisortusing added pre-commit hooks, so formatting and import ordering are checked on every commit rather than caught in review.Changes:
.pre-commit-config.yaml— new file; runsblack(25.1.0) andsort(5.13.2) as pre-commit hookspyproject.toml— adds[tool.black](line-length 88, py310/py311) and[tool.isort](black-compatible profile, dingo as first-party) config sections; addsisortandpre-committo dev dependencies.github/workflows/pytest.yml— adds a lint CI job that runsblack --checkandisort --check --diff, blocking PRs that aren't compliantAll files had to be reformatted such that the new CI test passes.
To set this up locally, developers have to run the following once:
The above instructions were added to the documentation. After initializing pre-commit, every commit looks like this:

If e.g.
isortfails, the commit is rejected andisortis automatically applied to the files where it failed. The modified files can be added to git and committed again.Note: When the pre-commit hook is activated, it only runs on files which are staged (i.e. files with changes to be committed). This means that if you merged in updates from another branch (e.g. main) which haven't been formatted and then only files with merge conflicts get staged in the next commit, the hook will format the modified files, but non-staged files from the merge might still need the formatting to be applied. If this is not done manually, the CI test will fail, despite the pre-commit hooks passing locally.