microsoft / vscode-isort

Import sorting for python using the isort library.
https://marketplace.visualstudio.com/items?itemName=ms-python.isort
MIT License
86 stars 20 forks source link

Filename override is intended only for stream (-) sorting. #317

Closed withgod84 closed 7 months ago

withgod84 commented 1 year ago

When I try to organize import, isort does not work even for simple example and I got the following error.

2023-08-23 17:29:29.337 [info] [Trace - 5:29:29 PM] Received notification 'window/logMessage'.
2023-08-23 17:29:29.337 [info] python -m isort - --profile black --filename SubTest.py
2023-08-23 17:29:29.338 [info] [Trace - 5:29:29 PM] Received notification 'window/logMessage'.
2023-08-23 17:29:29.338 [info] CWD Linter: /home/xxx/git2
2023-08-23 17:29:29.339 [info] [Trace - 5:29:29 PM] Received notification 'window/logMessage'.
2023-08-23 17:29:29.339 [info] ERROR: Filename override is intended only for stream (-) sorting.

According to log, giving filename option make the problem as I run the following command in terminal without "--filename", It works. python -m isort - --profile black --filename SubTest.py

I searched the error message and it seems that the extension use option 'filename' wrongly. filename option is used for streaming, not modified file. I recommend to remove "--filename" option. Please refer https://github.com/PyCQA/isort/blob/main/isort/main.py#1164

karthiknadig commented 1 year ago

@withgod84 We use streaming mode in the extension, so --filename being passed in here is correct. Can you share the full log? I would like to see the settings being passed in.

yzhang-gh commented 11 months ago

I have seen exactly the same issue. And I found it is caused by the --profile black argument which is configured in the setting isort.args.

karthiknadig commented 11 months ago

@yzhang-gh You will get that error if you put it in args like this ["--profile black"] which is wrong, it should be added like this ["--profile", "black"].

The space (`) between--profileandblackwhen you put it like["--profile black"]causesisort` to think this is a filename.

yzhang-gh commented 11 months ago

Amazing, it works now. I did this because the Black Formatter seems not to have this problem (with -l 120), just like the behavior of the shell=True in subprocess.run.