Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

isort --profile black produces long lines #2281

Open
bje- opened this issue Jul 22, 2024 · 8 comments
Open

isort --profile black produces long lines #2281

bje- opened this issue Jul 22, 2024 · 8 comments

Comments

@bje-
Copy link

bje- commented Jul 22, 2024

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)

@Helveg
Copy link

Helveg commented Jul 28, 2024

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

@bje-
Copy link
Author

bje- commented Jul 28, 2024

isort, shown with isort --show-config.

@Helveg
Copy link

Helveg commented Jul 28, 2024

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?

@bje-
Copy link
Author

bje- commented Jul 29, 2024

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

@Helveg
Copy link

Helveg commented Jul 29, 2024

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

@bje-
Copy link
Author

bje- commented Jul 29, 2024

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  -

@Helveg
Copy link

Helveg commented Jul 30, 2024

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,
}

@bje-
Copy link
Author

bje- commented Jul 30, 2024

Many thanks for getting to the bottom of this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants