Auto sorting of imports in a Python file in Vscode upon autosave

460 Views Asked by At

I recently started to use VSCode for python projects and there are a lot of features that I like about it. I recently started exploring how to achieve auto code formatting when code is auto saved and the one thing that is still eluding me is the auto sort of imports.

I can achieve auto sorting only when I explicitly tell VSCode to save or use the "Sort Imports" menu option. This is what my settings.json file looks like:

"python.linting.flake8Args": [],
"[python]": {
    "editor.formatOnSave": true,
    "editor.codeActionsOnSave": {
        "source.organizeImports": true,
    },
    "editor.formatOnType": true,
    "files.trimTrailingWhitespace": true,
    "editor.defaultFormatter": null
},
"python.formatting.provider": "black",
"isort.args": ["--profile", "black"]

I don't get it. Can anyone out there get isort to kick in on auto save? Note: I also have autosave only occurring when there is a 'onFocusChange' event.

0

There are 0 best solutions below