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

Import with python #407

Open Jacques2101 opened 8 months ago

Jacques2101 commented 8 months ago

Hi, I hope I am in the good place (I have contacted VSCode...).

I am trying to type this code:

import sys

import pandas as pd
sys.path.append(r'C:\Portef\utils')
from functions import lecture_bdd  # type: ignore

but the line with from functions import lecture_bdd is always copied in the 1st line as I am in auto-saved mode I suppose...So generate an error message. The code that is automatically displayed is:

from functions import lecture_bdd  # type: ignore
import sys
import pandas as pd
sys.path.append(r'C:\Portef\utils')

Is this a bug ??? thanks for your help

karthiknadig commented 8 months ago

@Jacques2101 This really depends on what settings you have. Share your setting.json, there should be at least two of them if not more: User Settings, and workspace settings.

Jacques2101 commented 8 months ago

user settings (file named setting.json):

{
    "python.autoComplete.addBrackets": true,
    "python.analysis.completeFunctionParens": true,
    "notebook.lineNumbers": "on",
    "editor.fontSize": 14,
    "window.zoomLevel": 1,
    "jupyter.askForKernelRestart": false,
    "jupyter.widgetScriptSources": [
        "jsdelivr.com",
        "unpkg.com"
    ],
    "jupyter.runStartupCommands": [
        "%matplotlib inline",
        "%load_ext autoreload",
        "%autoreload 2"
    ],
    "material-icon-theme.folders.associations": {},
    "jupyter.themeMatplotlibPlots": true,
    "workbench.list.openMode": "doubleClick",
    "workbench.preferredDarkColorTheme": "Visual Studio Dark",
    "workbench.tree.indent": 5,
    "notebook.cellToolbarVisibility": "hover",
    "settingsSync.ignoredExtensions": [],
    "notebook.cellToolbarLocation": {
        "default": "right",
        "jupyter-notebook": "right"
    },
    "explorer.confirmDelete": false,
    "search.showLineNumbers": true,
    "notebook.outline.showCodeCells": true,
    "notebook.showFoldingControls": "always",
    "bracket-pair-colorizer-2.forceUniqueOpeningColor": true,
    "dash.exactDocset": true,
    "editor.tabCompletion": "on",
    "cSpell.language": "fr-FR,fr,en,en-GB,en-US",
    "editor.formatOnPaste": true,
    "editor.formatOnSave": true,
    "workbench.commandPalette.preserveInput": true,
    "cSpell.patterns": [],
    "cSpell.enabledLanguageIds": [
        "asciidoc",
        "c",
        "cpp",
        "csharp",
        "css",
        "git-commit",
        "go",
        "graphql",
        "handlebars",
        "haskell",
        "html",
        "jade",
        "java",
        "javascript",
        "javascriptreact",
        "json",
        "jsonc",
        "latex",
        "less",
        "markdown",
        "php",
        "plaintext",
        "python",
        "pug",
        "restructuredtext",
        "rust",
        "scala",
        "scss",
        "text",
        "typescript",
        "typescriptreact",
        "yaml",
        "yml",
        "jupyter"
    ],
    "cSpell.languageSettings": [
        {
            "languageId": "python",
            "allowCompoundWords": false,
            "includeRegExpList": [
                "comments"
            ]
        }
    ],
    "kite.showWelcomeNotificationOnStartup": false,
    "terminal.integrated.inheritEnv": false,
    "workbench.editorAssociations": {
        "*.xlsx": "gc-excelviewer-excel-editor"
    },
    "tabnine.experimentalAutoImports": true,
    "explorer.confirmDragAndDrop": false,
    "editor.renderWhitespace": "all",
    "gitlens.defaultDateShortFormat": "D MYMM YYYY",
    "gitlens.defaultDateFormat": "D MMMM YYYY",
    "bracket-pair-colorizer-2.depreciation-notice": false,
    "material-icon-theme.activeIconPack": "vue_vuex",
    "cSpell.userWords": [
        "OECD",
        "streamlit",
        "updatés"
    ],
    "workbench.iconTheme": "vscode-great-icons",
    "editor.stickyTabStops": true,
    "editor.cursorStyle": "block",
    "files.autoSave": "afterDelay",
    "material-icon-theme.folders.color": "#7cb342",
    "material-icon-theme.opacity": 1,
    "material-icon-theme.hidesExplorerArrows": false,
    "vsicons.projectDetection.autoReload": true,
    "vsicons.dontShowNewVersionMessage": true,
    "cSpell.enableFiletypes": [
        "!markdown"
    ],
    "workbench.productIconTheme": "macos-modern",
    "[python]": {
        "editor.formatOnType": true,
        "editor.defaultFormatter": "ms-python.autopep8"
    },
    "indentRainbow.tabmixColor": "",
    "indentRainbow.indicatorStyle": "light",
    "jupyter.interactiveWindow.creationMode": "perFile",
    "jupyter.interactiveWindow.textEditor.magicCommandsAsComments": true,
    "python.formatting.autopep8Args": [
        "\"--max-line-length=120\""
    ],
    "python.analysis.packageIndexDepths": [
        {
            "name": "sklearn",
            "depth": 3,
            "includeAllSymbols": true
        },
        {
            "name": "matplotlib",
            "depth": 3,
            "includeAllSymbols": true
        },
        {
            "name": "scipy",
            "depth": 3,
            "includeAllSymbols": true
        },
        {
            "name": "django",
            "depth": 2,
            "includeAllSymbols": true
        }
    ],
    "pythonIndent.trimLinesWithOnlyWhitespace": true,
    "editor.unicodeHighlight.invisibleCharacters": false,
    "editor.unicodeHighlight.ambiguousCharacters": false,
    "git.autofetch": true,
    "workbench.colorTheme": "Default Dark+",
    "notebook.output.textLineLimit": 100,
    "editor.accessibilityPageSize": 50,
    "git.confirmSync": false,
    "editor.cursorSmoothCaretAnimation": "on",
    "notebook.scrolling.revealNextCellOnExecute": "firstLine",
    "workbench.editor.pinnedTabsOnSeparateRow": true,
    "python.autoComplete.extraPaths": [],
    "python.analysis.extraPaths": [],
    "editor.defaultFormatter": "ms-python.autopep8",
    "extensions.autoUpdate": "onlyEnabledExtensions",
    "editor.accessibilitySupport": "off",
    "python.analysis.autoFormatStrings": true,
    "mssql.connections": [
        {
            "server": "vestathena.database.windows.net",
            "database": "vestathena_db",
            "authenticationType": "SqlLogin",
            "user": "login_MAM_read",
            "password": "",
            "emptyPasswordInput": false,
            "savePassword": true,
            "profileName": "Base_fonds_interne"
        },
        {
            "server": "tcp:vestathena.database.windows.net,1433",
            "database": "vestathena_db",
            "authenticationType": "SqlLogin",
            "user": "login_MAM_read",
            "password": "",
            "emptyPasswordInput": false,
            "savePassword": true,
            "profileName": "Monceau"
        },
        {
            "server": "tcp:vestathena.database.windows.net,1433",
            "database": "multigestion_db",
            "authenticationType": "SqlLogin",
            "user": "login_MAM_read",
            "password": "",
            "emptyPasswordInput": false,
            "savePassword": true,
            "profileName": "MultiGestion"
        },
        {
            "server": "tcp:vestathena.database.windows.net,1433",
            "database": "multigestion_db",
            "authenticationType": "SqlLogin",
            "user": "login_MAM_read",
            "password": "",
            "emptyPasswordInput": false,
            "savePassword": true,
            "profileName": "Base_fonds_externe"
        }
    ],
    "mssql.objectExplorer.groupBySchema": false,
    "accessibility.signals.sounds.volume": 0,
    "liveshare.notebooks.allowGuestExecuteCells": true,
    "editor.minimap.enabled": false
}

workspace settings (file named workspace.json):

{
    "folders": [
        {
            "path": "/Users/jacques/Library/Mobile Documents/com~apple~CloudDocs/Projets"
        },
        {
            "path": "/Users/jacques/Library/CloudStorage/OneDrive-MonceauAssetManagement/Dossier Bloom/Fonds"
        },
        {
            "path": "../../../../CloudStorage/OneDrive-Bibliothèquespartagées-MonceauAssetManagement/Multigestion - Documents de gestion/Nouveau Produit Vie (MONCEAU ASSURANCES)/Code Python"
        }
    ],
    "settings": {
        "indentRainbow.errorColor": "rgba(128,32,32,0)",
        "indentRainbow.tabmixColor": "",
        "indentRainbow.indicatorStyle": "classic",
        "pythonIndent.trimLinesWithOnlyWhitespace": true,
        "workbench.editor.pinnedTabsOnSeparateRow": true,
        "cSpell.autoFormatConfigFile": true,
        "jupyter.themeMatplotlibPlots": true,
        "notebook.scrolling.revealNextCellOnExecute": "firstLine",
        "accessibility.signals.sounds.volume": 0, 
    }
}

others settings :

{
  "python.pythonPath": "/Users/jacques/opt/anaconda3/envs/Data/bin/python",
  "python.testing.pytestArgs": [
    "."
  ],
  "python.testing.unittestEnabled": false,
  "python.testing.nosetestsEnabled": false,
  "python.testing.pytestEnabled": false,
  "python.testing.promptToConfigure": false,
  "files.exclude": {
    "**/__pycache__": true,
    "**/.*": true
  },
  "editor.formatOnSave": true,
  "prettier.singleQuote": true,
  "editor.defaultFormatter": "ms-python.autopep8",
  "[python]": {
    "editor.defaultFormatter": "ms-python.autopep8"
  },
  "python.formatting.provider": "none",
  "auto-comment-blocks.singleLineBlockOnEnter": true,
  "jupyter.jupyterServerType": "local",
  "cSpell.words": [
    "dataframes",
    "SFDR",
    "streamlit",
    "updatés"
  ],
  "python.analysis.typeCheckingMode": "off",
  "cSpell.language": "fr-FR,fr,en,en-US,en-GB",
  "cSpell.enableFiletypes": [
    "!markdown"
  ],
  "indentRainbow.errorColor": "rgba(128,32,32,0)",
  "indentRainbow.tabmixColor": "",
  "indentRainbow.indicatorStyle": "classic",
  "pythonIndent.trimLinesWithOnlyWhitespace": true,
  "jupyter.kernels.excludePythonEnvironments": [
    "/usr/bin/python3"
  ],
  "[jsonc]": {
    "editor.defaultFormatter": "vscode.json-language-features"
  },
  "files.autoSave": "afterDelay",
  "editor.fontSize": 16,
  "editor.accessibilityPageSize": 50,
  "workbench.editor.pinnedTabsOnSeparateRow": true,
  "cSpell.enabled": true,
  "cSpell.autoFormatConfigFile": true,
  "python.analysis.autoFormatStrings": true,
  "jupyter.themeMatplotlibPlots": true,
  "notebook.scrolling.revealNextCellOnExecute": "firstLine",
  "audioCues.volume": 0,
  "python.analysis.autoImportCompletions": true
}
karthiknadig commented 8 months ago

@Jacques2101 How are you triggering import sorting? Can you share the output logs from Output > isort?

Jacques2101 commented 8 months ago

How to share it ?

karthiknadig commented 8 months ago

You can copy paste the content here, if it is too large save it to a text file and upload it here.

Jacques2101 commented 7 months ago

Finally I change the formatter from autopep8 to black and it seems to work. I don't know why

karthiknadig commented 7 months ago

You need to tell isortwhich formatted you are using via —profile argument. If you don’t the. It will assume things and try to format. It’s assumptions might work sometimes.