Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff extension configured as formatter but does not actually format Python files #653

Open
rohanbalkondekar opened this issue Dec 16, 2024 · 6 comments
Labels
question Asking for support or clarification

Comments

@rohanbalkondekar
Copy link

Image

Description:
I encountered a prompt in VSCode stating:

"Extension 'Ruff' is configured as formatter but it cannot format 'Python'-files."

Additional Context:

  • VSCode version:
    Version: 1.95.3
    Commit: f1a4fb101478ce6ec82fe9627c43efbf9e98c813
    Date: 2024-11-13T14:50:04.152Z
    Electron: 32.2.1
    ElectronBuildId: 10427718
    Chromium: 128.0.6613.186
    Node.js: 20.18.0
    V8: 12.8.374.38-electron.0
    OS: Linux x64 6.8.0-49-generic

  • Ruff extension version: ruff 0.6.8

  • Python version: 3.10.12

  • Operating system: Ubuntu Mate
    Distributor ID: Ubuntu
    Description: Ubuntu 22.04.5 LTS
    Release: 22.04
    Codename: jammy

@MichaReiser
Copy link
Member

MichaReiser commented Dec 20, 2024

Hi @rohanbalkondekar

I'm sorry that you're running into this. Would you mind sharing the ruff extension logs with us?

If you encounter any issues with the extension or the language server, please refer to the logs in the output panel in VS Code. You can access the logs by running the Ruff: Show logs command.

Could you also try using a more recent version of ruff?

@MichaReiser MichaReiser added the question Asking for support or clarification label Dec 20, 2024
@lig
Copy link

lig commented Jan 14, 2025

Same here on two different vscode configurations on different laptops.
How can I get those logs?

I've already configured Ruff extension to use bundled Ruff as was mentioned in another issue I've found earlier. Doesn't help.

@lig
Copy link

lig commented Jan 14, 2025

I've recreated venv and now it works. Have no idea what that was 🤷‍♂

@dhruvmanila
Copy link
Member

How can I get those logs?

You can refer to the troubleshooting guide for that.

I've recreated venv and now it works. Have no idea what that was 🤷‍♂

If possible, can you try removing the venv and see if it still works? It would be useful to know what this issue is about and how to resolve it. Do you have a ruff executable available on PATH globally (related ruff.importStrategy?

@lig
Copy link

lig commented Jan 21, 2025

I'll try to debug this on a second laptop.

Yes, I always have ruff installed via uv tool or pipx and another one in the project's venv.

@danieleds
Copy link

danieleds commented Jan 21, 2025

I'm using a vscode workspace with multiple projects - each project has its own .venv.

I'm not sure if this issue started appearing right after I switched to the vscode workspace project layout, or after that.

However, while debugging this issue, I noticed that when I tried running the command "Ruff: Restart Server", Ruff complained that it couldn't find the Python executable in the root of my workspace (instead of using the one in the sub-project).

Setting the ruff extension to use the bundled ruff did not help.

What helped was:

  • Created a dummy .venv at the root of my workspace
  • Restarted the ruff server
  • Create a .vscode/settings.json file with the following content, even if the same file with the same content already existed under the root vscode settings of the workspace:
{
    "[python]": {
        "editor.formatOnSave": true,
        "editor.defaultFormatter": "charliermarsh.ruff"
    }
}

Is it possible that the ruff extension is not playing well with vscode workspaces?

Related: #654 (but I'm developing locally, no remote server involved)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Asking for support or clarification
Projects
None yet
Development

No branches or pull requests

5 participants