Debian Codegraph @

docs/configuration/black_compatibility.md

raw
1 ![isort loves black](https://raw.githubusercontent.com/pycqa/isort/main/art/isort_loves_black.png)
2
3 # Compatibility with black
4
5 Compatibility with black is very important to the isort project and comes baked in starting with version 5.
6 All that's required to use isort alongside black is to set the isort profile to "black".
7
8 !!! tip
9 Beyond the profile, it is common to set [skip_gitignore](./options.md#skip-gitignore) (which is not enabled by default for isort as it requires git to be installed) and [line_length](./options.md#line-length) as it is common to deviate from black's default of 88.
10
11
12 ## Using a config file (such as .isort.cfg)
13
14 For projects that officially use both isort and black, we recommend setting the black profile in a config file at the root of your project's repository.
15 That way it's independent of how users call isort (pre-commit, CLI, or editor integration) the black profile will automatically be applied.
16
17 For instance, your _pyproject.toml_ file would look something like
18
19 ```ini
20 [tool.isort]
21 profile = "black"
22 ```
23
24 Read More about supported [config files](./config_files.md).
25
26 ## CLI
27
28 To use the profile option when calling isort directly from the commandline simply add the --profile black argument: `isort --profile black`.
29
30 A demo of how this would look like in your _.travis.yml_
31
32 ```yaml
33 language: python
34 python:
35 - "3.10"
36
37 install:
38 - pip install -r requirements-dev.txt
39 - pip install isort black
40 - pip install coveralls
41 script:
42 - pytest my-package
43 - isort --profile black my-package
44 - black --check --diff my-package
45 after_success:
46 - coveralls
47
48 ```
49
50 See [built-in profiles](./profiles.md) for more profiles.
51
52 ## Integration with pre-commit
53
54 You can also set the profile directly when integrating isort within pre-commit.
55
56 ```yaml
57 - repo: https://github.com/pycqa/isort
58 rev: 6.0.1
59 hooks:
60 - id: isort
61 args: ["--profile", "black", "--filter-files"]
62 ```