astral-sh / ruff-vscode

A Visual Studio Code extension with support for the Ruff linter.
Other
1.13k stars 54 forks source link

There is no formatter for 'python' files installed #596

Closed issam-seghir closed 2 months ago

issam-seghir commented 2 months ago

i have the same problem mentioned in the issue below i'm using the latest version : v2024.42.0 and ruff = "^0.6.2"

Originally posted by @issam-seghir in https://github.com/astral-sh/ruff-vscode/issues/460#issuecomment-2319382190

system info :

Version: 1.92.2 (user setup) Commit: fee1edb8d6d72a0ddff41e5f71a671c23ed924b9 Date: 2024-08-14T17:29:30.058Z Electron: 30.1.2 ElectronBuildId: 9870757 Chromium: 124.0.6367.243 Node.js: 20.14.0 V8: 12.4.254.20-electron.0 OS: Windows_NT x64 10.0.19045

CPUs AMD Ryzen 5 PRO 4650G with Radeon Graphics (12 x 3693)
GPU Status 2d_canvas: enabled canvas_oop_rasterization: enabled_on direct_rendering_display_compositor: disabled_off_ok gpu_compositing: enabled multiple_raster_threads: enabled_on opengl: enabled_on rasterization: enabled raw_draw: disabled_off_ok skia_graphite: disabled_off video_decode: enabled video_encode: enabled vulkan: disabled_off webgl: enabled webgl2: enabled webgpu: enabled webnn: disabled_off
Load (avg)  
Memory (System) 15.33GB (3.47GB free)
Screen Reader no
VM 0%
dhruvmanila commented 2 months ago

Thanks for opening this issue. Can you provide a way to reproduce this for me? I'm interested in:

  1. VS Code settings (ideally only the ones relevant to Ruff and Python extension)
  2. Ruff configuration file, if any
  3. Ruff logs, refer to the troubleshooting guide
  4. Source code in which the problem is present
lukaspiatkowski commented 2 months ago

I had the same problem using those versions. In my case it was that the Ruff VSCode plugin at some point started to treat the ruff.interpreter config differently. I had to change the value from .venv/bin/python to ${workspaceFolder}/.venv/bin/python for this to get fixed.

dhruvmanila commented 2 months ago

@lukaspiatkowski Yes, that's resolved in https://github.com/astral-sh/ruff-vscode/pull/553 which provides the context.

issam-seghir commented 2 months ago

i'm on windows , my python path when using poetry env is : .venv/Scripts/python , so i use this config

"ruff.importStrategy": "fromEnvironment",
    "ruff.interpreter": [
        "${workspaceFolder}/.venv/Scripts/python"
    ], 

but this does not fix the problem for me :

python log :

2024-09-04 15:55:57.491 [error] Reading directory to watch failed [Error: ENOENT: no such file or directory, scandir 'e:\Documents\Vs Code Projects\Chatbot\LLM\.pixi\envs'
    at Object.readdirSync (node:fs:1509:26)
    at t.readdirSync (node:electron/js2c/node_init:2:11418)
    at c:\Users\GAMING\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\out\client\extension.js:2:586747
    at c:\Users\GAMING\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\out\client\extension.js:2:586938
    at Array.map (<anonymous>)
    at d.initWatchers (c:\Users\GAMING\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\out\client\extension.js:2:586656)
    at async d.ensureWatchersReady (c:\Users\GAMING\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\out\client\extension.js:2:543067)] {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'scandir',
  path: 'e:\\Documents\\Vs Code Projects\\Chatbot\\LLM\\.pixi\\envs'
}
2024-09-04 15:55:57.491 [error] Dir "e:\Documents\Vs Code Projects\Chatbot\LLM\.pixi\envs" is not watchable (directory does not exist)
2024-09-04 15:55:57.491 [info] Default formatter is set to charliermarsh.ruff for workspace e:\Documents\Vs Code Projects\Chatbot\LLM
2024-09-04 15:55:57.524 [info] Python interpreter path: .\.venv\Scripts\python.exe
2024-09-04 15:55:58.424 [info] > E:\Apps\scoop\apps\pyenv\current\pyenv-win\bin\pyenv which python
2024-09-04 15:55:58.424 [info] cwd: e:\Documents\Vs Code Projects\Chatbot\LLM
2024-09-04 15:55:58.474 [info] > conda info --json
2024-09-04 15:55:59.017 [info] > ~\.condarc\Scripts\conda.exe info --json
2024-09-04 15:56:09.584 [info] Starting Pylance language server.
2024-09-04 15:57:42.883 [info] Discover tests for workspace name: LLM - uri: e:\Documents\Vs Code Projects\Chatbot\LLM\app\modules\conversation_assistant.py
2024-09-04 15:57:42.924 [info] > pixi --version
2024-09-04 15:57:42.925 [error] Error: spawn pixi ENOENT
    at Process.ChildProcess._handle.onexit (node:internal/child_process:286:19)
    at onErrorNT (node:internal/child_process:484:16)
    at processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4058,
  code: 'ENOENT',
  syscall: 'spawn pixi',
  path: 'pixi',
  spawnargs: [ '--version' ]
}
2024-09-04 15:57:42.925 [warning] could not find a pixi interpreter for the interpreter at e:\Documents\Vs Code Projects\Chatbot\LLM\.venv\Scripts\python.exe
2024-09-04 15:57:42.959 [info] > "e:/Documents/Vs Code Projects/Chatbot/LLM/.venv/Scripts/activate.bat" && echo 'e8b39361-0157-4923-80e1-22d70d46dee6' && python ~/.vscode/extensions/ms-python.python-2024.12.3-win32-x64/python_files/printEnvVariables.py
2024-09-04 15:57:42.959 [info] shell: commandPrompt
2024-09-04 15:57:43.883 [warning] could not find a pixi interpreter for the interpreter at e:\Documents\Vs Code Projects\Chatbot\LLM\.venv\Scripts\python.exe
2024-09-04 15:57:43.893 [info] > "e:\Documents\Vs Code Projects\Chatbot\LLM\.venv\Scripts\python.exe" ~\.vscode\extensions\ms-python.python-2024.12.3-win32-x64\python_files\testing_tools\run_adapter.py discover pytest -- --rootdir "e:\Documents\Vs Code Projects\Chatbot\LLM" -s --cache-clear
2024-09-04 15:57:43.893 [info] cwd: e:\Documents\Vs Code Projects\Chatbot\LLM
"[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff",
        "editor.codeActionsOnSave": {
            "source.fixAll": "explicit",
            "source.organizeImports": "explicit"
        },
    },
    "python.analysis.inlayHints.functionReturnTypes": true,
    "python.analysis.inlayHints.variableTypes": true,
    "python.languageServer": "Pylance",
    "python.analysis.logLevel": "Trace",
    "python.analysis.typeCheckingMode": "standard",
    "python.testing.pytestEnabled": true,
    "python.analysis.autoImportCompletions": true,
    "python.analysis.fixAll": [
        "source.unusedImports"
    ],
    "python.venvFolders": [
        "${workspaceFolder}\\.venv"
    ],
    "python.analysis.inlayHints.pytestParameters": true,
    "python.analysis.inlayHints.callArgumentNames": "all",
         "files.exclude": {
        // for python
        "**/__pycache__": true,
        "**/.cache": true,
        "**/.coverage": true,
        "**/.coverage.*": true,
        "**/.hypothesis": true,
        "**/.mypy_cache": true,
        "**/.nox": true,
        "**/.pytest_cache": true,
        "**/.ruff_cache": true,
        "**/.tox": true
        // "**/node_modules": true
    },
    "ruff.lineLength": 120,
    "ruff.showNotifications": "always",
    "ruff.importStrategy": "fromEnvironment",
    "ruff.interpreter": [
        "${workspaceFolder}/.venv/Scripts/python"
    ],
       "ruff.lint.run": "onSave",
    "ruff.nativeServer": "on",
[lint]
select = ["ALL"]
[tool.poetry.group.dev.dependencies]
ruff = "^0.6.2"
pre-commit = "^3.8.0"
mypy = "^1.11.2"
isort = "^5.13.2"
types-ujson = "^5.10.0.20240515"
types-requests = "^2.32.0.20240712"

[tool.ruff]
line-length = 88
exclude = [".git", "__pycache__", ".mypy_cache", ".pytest_cache"]
select = [
    "E",  # pycodestyle errors
    "W",  # pycodestyle warnings
    "F",  # pyflakes
    # "I",  # isort
    "C",  # flake8-comprehensions
    "B",  # flake8-bugbear
]
ignore = [
    "B904",
    "B006",
    "E501",  # line too long, handled by black
    "B008",  # do not perform function calls in argument defaults
    "C901",  # too complex
]

[tool.ruff.per-file-ignores]
"__init__.py" = ["F401"]

[tool.black]
line-length = 88
target-version = [ "py310", "py311" ]
exclude = "((.eggs | .git | .pytest_cache | build | dist))"

[tool.isort]
profile = "black"

[tool.poetry.scripts]
start = "uvicorn app.main:app --reload"

[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

image

dhruvmanila commented 2 months ago

python log :

These are Python logs. I'm specifically asking for Ruff logs. Here's how to get it:

how_to_get_ruff_logs

What's the version of your Ruff extension?

how_to_get_ruff_extension_version

Can you provide the list of extensions that you've installed? You can get that via code --list-extensions command.

issam-seghir commented 2 months ago

@dhruvmanila, the extension is working after VS Code last update and restarting my computer.

image

dhruvmanila commented 2 months ago

Perfect! Thanks for following up. I'll mark this issue as resolved then.