I am facing a formatting issue. The default behavior of python.sortImports
is to organize stdlib, 3rd party, and user modules.
However, it moves my user modules above the 3rd part modules in alphabetical order which is not according to PEP8. And, it follows PEP8 when I use relative imports which is making things more difficult.
Here, is the desired output.
from django.urls import path
from rest_framework.authtoken import views
from rest_framework.urlpatterns import format_suffix_patterns
from customauth.views import ListUsers, RegisterUser
customauth
is a user defined Django app, rest of them are 3rd part as you can see.
Actual output of python.sortImports
.
from customauth.views import ListUsers, RegisterUser
from django.urls import path
from rest_framework.authtoken import views
from rest_framework.urlpatterns import format_suffix_patterns
My VS Code settings are mentioned below.
"editor.defaultFormatter": "ms-python.python",
"files.autoSave": "onWindowChange",
"python.linting.flake8Enabled": true,
"python.analysis.inlayHints.functionReturnTypes": true,
"python.analysis.inlayHints.variableTypes": true,
"[python]": {
"editor.defaultFormatter": "ms-python.python",
"editor.codeActionsOnSave": {
"source.organizeImports": true,
"python.sortImports": true
}
},
"python.globalModuleInstallation": true,
"python.autoComplete.extraPaths": [
"/usr/local/lib/python3.10/site-packages/",
],
"python.analysis.extraPaths": [
"/usr/local/lib/python3.10/site-packages/"
],
"isort.check": true,
"isort.args": ["--profile, "django"],
"python.analysis.autoImportCompletions": true,
"python.analysis.packageIndexDepths": [
{
"name": "sklearn",
"depth": 2
},
{
"name": "matplotlib",
"depth": 2
},
{
"name": "scipy",
"depth": 2
},
{
"name": "django",
"depth": 3
}
],
"python.analysis.indexing": true,
"python.analysis.completeFunctionParens": true
Note: I have figured out that this is an isort
issue. But do not know why this happening.