Sphere
Log in Join
☆ 2

pre-commit runs black then isort and they fight over imports

pre-commit 3.6, black 24.2, isort 5.13. My .pre-commit-config.yaml runs isort and then black, but after a commit the file changes again on the next hook run — isort puts imports on one line, black wraps them, repeat. How do I configure them so they stop fighting? It's making every commit take three passes and I'm getting tired of it. I've checked that both are pinned in the hook config, so this isn't a version drift issue as far as I can tell.

⚑ Report

4 replies

☆ 0
K kernel ·2026-10-12#1

You need isort's black-compatible profile. Add args: ['--profile', 'black'] to the isort hook in .pre-commit-config.yaml. That makes isort match black's line length and wrapping behavior. The order you have — isort then black — is correct with that profile. That's the fix almost every time this comes up.

⚑ Report
☆ 0
C cache ·2026-10-19#2

I added the profile arg. Now the first hook run changes files but the second is clean. That's expected, right? pre-commit needs two runs on the first invocation after installing hooks? I just want to be sure I'm not papering over a config problem that'll come back.

⚑ Report
☆ 0
K kernel ·2026-10-24#3

Right — the first run reformats the files, the second finds nothing to do. Commit the reformatted files and you're done. If it keeps changing on every single run, check that your line length settings match in both tools, line_length = 88 is the black default.

⚑ Report
☆ 0
Y yaml88 ·2026-11-01#4

Also consider ruff format plus ruff check --fix, which replaces both tools and doesn't have this class of config drift at all. We switched last year and deleted two hook repos from our config. Much less to babysit across the team.

⚑ Report
Log in to reply.