isort icon indicating copy to clipboard operation
isort copied to clipboard

isort --profile black produces long lines

Open bje- opened this issue 1 year ago • 8 comments

I have line_length set to 79.

When formatting this code with isort --profile black:

from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,
                           pv_limit, wind_limit)

I get:

from nemo.polygons import WILDCARD, cst_limit, offshore_wind_limit, pv_limit, wind_limit

(which is 89 characters long)

bje- avatar Jul 22 '24 23:07 bje-

How exactly did you set line_length? Did you set it for black or for isort?

Helveg avatar Jul 28 '24 15:07 Helveg

isort, shown with isort --show-config.

bje- avatar Jul 28 '24 21:07 bje-

I can't reproduce your issue, with either the following Python snippet:

import isort
code = """from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,
                           pv_limit, wind_limit)"""
isort.code(code, profile="black", line_length=79)

or the following bash snippet:

printf "from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,\n                  pv_limit, wind_limit)" | isort --profile=black --line-length=79 -

the output is always:

from nemo.polygons import (
    WILDCARD,
    cst_limit,
    offshore_wind_limit,
    pv_limit,
    wind_limit,
)

Is your isort version up to date? If so, can you try passing the arguments like shown in my snippets. If none of that works, could you fully reproduce how you are setting and verifying the isort settings?

Helveg avatar Jul 28 '24 22:07 Helveg

isort --version says 5.13.2.

isort --show-config | grep line_length says:

    "line_length": 79,

Your bash snippet works for me, but if I remove the explicit --line-length argument and rely on what is shown in the config output:

printf "from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,\n                  pv_limit,
wind_limit)" | isort --profile=black  -

produces:

from nemo.polygons import WILDCARD, cst_limit, offshore_wind_limit, pv_limit, wind_limit

bje- avatar Jul 29 '24 04:07 bje-

Ok, can you provide me everything I need to set my config exactly the same way?

Helveg avatar Jul 29 '24 14:07 Helveg

python3 -m venv myenv
. myenv/bin/activate
pip install isort
printf "from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,\n                  pv_limit,
wind_limit)" | isort --profile=black  -

bje- avatar Jul 29 '24 21:07 bje-

Ok, so you're not actually setting isort's line_length to anything. In that case everything is working as expected:

The default line_length is indeed 79 characters, which is what isort --show-config shows you. But during the command you are using --profile=black. Using isort --show-config --profile=black you will see that that profile sets a line_length of 88. And the line you produce is not 89, but 88 characters long:

isort --show-config --profile=black
{
  ...
   "line_length": 88,
  ...
}

you can test this by adding 1 character _ to the last import:

printf "from nemo.polygons import (WILDCARD, cst_limit, offshore_wind_limit,\n
         pv_limit,
wind_limit_)" | isort --profile=black  -
from nemo.polygons import (
    WILDCARD,
    cst_limit,
    offshore_wind_limit,
    pv_limit,
    wind_limit_,
)

As you can see, everything is working as expected, your test input just happened to be in the Goldilock zone to mislead you 😂 Keep in mind that the profile option works by setting configuration options. These are the options that the black profile sets:

black = {
    "multi_line_output": 3,
    "include_trailing_comma": True,
    "force_grid_wrap": 0,
    "use_parentheses": True,
    "ensure_newline_before_comments": True,
    "line_length": 88,
}

Helveg avatar Jul 30 '24 12:07 Helveg

Many thanks for getting to the bottom of this.

bje- avatar Jul 30 '24 13:07 bje-

@bje- It appears that this has been resolved and is not an issue. If this is correct, please close this issue to reduce the backlog of issues to address. Thanks!

kurtmckee avatar Jan 08 '25 12:01 kurtmckee