How to get isort to recognize the line_length option in my config file?

339 views Asked by At

I am trying to configure isort so that it runs with pre-commit alongside black for my project. I've set up a pyproject.toml to hold the settings. One of the settings I've specified is line_length, at 90. Whenever I run isort on my project, it ignores the line_length setting and changes imports so that they satisfy the default 79 characters. Because of this, pre-commit will always fail during the isort hook if I have an import line greater than 79 characters.

Here's my pyproject.toml settings, where I've set line_length to 90 characters:

[tool.isort]
profile = "black"
multi_line_output = 3
ignore_trailing_comma = true
line_length = 90
skip = [".gitignore", ".dockerignore"]

And this is the import that has a length of 84 characters and should not be changed:

from my_project_is_amazing.custom_permissions import NotificationSettingsPermission

When I run the command isort ./notification_settings.py, isort "fixes" the import:

from my_project_is_amazing.custom_permissions import (
    NotificationSettingsPermission
)

I've confirmed from the isort documentation that I have the correct config name for Line Length. Also, I've tried specifying the Line Length inline with the command (isort -w 90 ./notification_settings.py) which does work, ignoring the import line. However, that won't work when I run isort within pre-commit.

1

There are 1 answers

0
James Andrews On

Well, I feel silly. I had previously configured my isort settings in a .isort.cfg file before moving them to the pyproject.toml. But I never specified the line_length in it, and I never deleted the old config file. So when I went to run isort, .isort.cfg takes priority over pyproject.toml. I've deleted the old config file, and isort runs as expected!