microsoft / vscode-isort

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

`--profile black` doesn't work with bundled `isort` #269

Closed GarrisonD closed 1 year ago

GarrisonD commented 1 year ago

In Output I can see:

/usr/local/bin/python3 -m isort - --profile black --filename /some-dir/some-file.py

If I copy this line and just paste in the terminal I get:

/usr/local/opt/python@3.11/bin/python3.11: No module named isort

But somehow imports get reformatted (just alphabetically but anyway) in VS Code... That's 🪄

karthiknadig commented 1 year ago

@GarrisonD The bundled isort is not in your environment, so you cannot run the command line as is, if you want this to work from command line then do this:

  1. install isort in your environment
  2. Set isort.importStrategy to fromEnvironment

The way we use the bundled isort is by adding it to path when running the server. This is done avoid isort or its dependencies interfering with your environment. In the logs we print out the equivalent command for everything the server runs.

GarrisonD commented 1 year ago

Makes sense. But why doesn't --profile black work with bundled isort? Isn't it just a set of configurations being applied?

karthiknadig commented 1 year ago

Share your full settings and logs, it should work: image

This is how I have it in my settings:

    "isort.args": ["--profile", "black"],
karthiknadig commented 1 year ago

if you set "isort.logLevel": "debug", it should give you detailed info on where it is picking up each setting.

GarrisonD commented 1 year ago

In Output I see that this option is passed but the result is different to isort that I run in a Docker container. The only difference I can think about is that on the host I don't have any libs and in the Docker container I have:

karthiknadig commented 1 year ago

Set "isort.logLevel": "debug" and see the logs, isort looks for settings from several locations including your home directory. I recommend comparing the settings it finds between the two environments.

When I say settings i don't mean isort extension setting. with debug mode set the extension will run isort --show-config, I recommend getting log and check between the two environments and seeing why it differs.

GarrisonD commented 1 year ago

@karthiknadig With your advice, I could investigate and solve all the issues. Thanks a lot!