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

Using isort with Jupyter Notebooks #315

Closed jvhoffbauer closed 10 months ago

jvhoffbauer commented 1 year ago

Is it possible to use isort with Jupyter Notebooks in VSCode?

karthiknadig commented 1 year ago

You should be able to trigger sort import for Notebooks.

@Yoyokrazy This is the current selection criteria in the doc selector: https://github.com/microsoft/vscode-isort/blob/fe9b8985c0c09bf5952b4ed5de68c30c74aed365/src/common/utilities.ts#L75-L78

This should be enough as far as I understand.

alexdauenhauer commented 11 months ago

@karthiknadig are you saying it should already work out of the box? maybe I misunderstood your comment. It definitely does not currently run on jupyter notebooks for me

EDIT: I think you need to put this in your settings to make it work?

"isort.args": ["--profile", "black"]
karthiknadig commented 11 months ago

@alexdauenhauer You should be able to see what was triggered in the Output > isort logs

karthiknadig commented 10 months ago

The command you need to call is Organize Imports

jtele2 commented 2 months ago

Can this be done on save? I can't seem to get it to work on save.

nonoash commented 1 month ago

i have this setting for notebooks in my settings.json but i can't make it works OnSave. It's fine with editor.

"notebook.codeActionsOnSave": {
    "notebook.source.organizeImports": "explicit"
  },
  "isort.args": [
    "--profile",
    "black"
  ],