| 1 |
Using isort with pre-commit |
| 2 |
=========================== |
| 3 |
|
| 4 |
isort provides official support for [pre-commit](https://pre-commit.com/). |
| 5 |
|
| 6 |
## isort pre-commit step |
| 7 |
|
| 8 |
To use isort's official pre-commit integration add the following config: |
| 9 |
|
| 10 |
```yaml |
| 11 |
- repo: https://github.com/pycqa/isort |
| 12 |
rev: 6.1.0 |
| 13 |
hooks: |
| 14 |
- id: isort |
| 15 |
name: isort (python) |
| 16 |
``` |
| 17 |
|
| 18 |
under the `repos` section of your projects `.pre-commit-config.yaml` file. Optionally if you want to have different hooks |
| 19 |
over different file types (ex: python vs cython vs pyi) you can do so with the following config: |
| 20 |
|
| 21 |
```yaml |
| 22 |
- repo: https://github.com/pycqa/isort |
| 23 |
rev: 6.1.0 |
| 24 |
hooks: |
| 25 |
- id: isort |
| 26 |
name: isort (python) |
| 27 |
- id: isort |
| 28 |
name: isort (cython) |
| 29 |
types: [cython] |
| 30 |
- id: isort |
| 31 |
name: isort (pyi) |
| 32 |
types: [pyi] |
| 33 |
``` |
| 34 |
|
| 35 |
## seed-isort-config |
| 36 |
|
| 37 |
Older versions of isort used a lot of magic to determine import placement, that could easily break when running on CI/CD. |
| 38 |
To fix this, a utility called `seed-isort-config` was created. Since isort 5 however, the project has drastically improved its placement |
| 39 |
logic and ensured a good level of consistency across environments. |
| 40 |
If you have a step in your pre-commit config called `seed-isort-config` or similar, it is highly recommend that you remove this. |
| 41 |
It is guaranteed to slow things down, and can conflict with isort's own module placement logic. |