astral-sh/ruff-vscode

VSCode ruff extension NOT formatting Notebooks (windows?!)

Julian-J-S opened this issue ยท 5 comments

I regularly experience problems with the VSCode ruff extension on windows where it does NOT format notebook files (.ipynb).

Super easy example (probably not reproducable for most but happens to me all the time)
Notebook (format_me.ipynb) with a single code cell)

print(         "Hello, World!"            )

Result: nothing happens

Format Invocation:

  • VSCode Extension
    image

Additional Info:

  • only notebook affected; same code as ".py" works
  • exact same notebook formats on MacOS! (not working on windows; might be something else but noteworthy)
  • no ruff cli installed. Only the extension; vscode extensin: v2024.40.0

Atteched ipynb file as json because attaching ipynb extension not possible :D

format_me.json

  • exact same notebook formats on MacOS! (not working on windows; might be something else but noteworthy)

Is the VS Code / Ruff version the same on MacOS as the one on Windows? Can you try including the config file as below in a ruff.toml file, restart the extension and try formatting?

extend-include = ["*.ipynb"]

hi @dhruvmanila

when I add this file I sometimes get this
image

Also just observed:
On MacOS every keystroke in a ".py" or "ipynb" file triggers some output in the VSCode "OUTPUT" window (vscode Ruff: Show logs)

NOTHING happends when I do that on windows.
However, formatting a ".py" file still works ๐Ÿ˜ฑ

when I add this file I sometimes get this

Are you referring to ruff.toml file?

Also just observed:
On MacOS every keystroke in a ".py" or "ipynb" file triggers some output in the VSCode "OUTPUT" window (vscode Ruff: Show logs)

Can you provide the output?

Additionally, can you also provide the VS Code settings used related to Ruff and Python? You might also find the troubleshooting section useful for debugging and providing detailed logs.

You are right. I was missing the extend-include = ["*.ipynb"]
I could swear this worked on my Mac without that at some point ๐Ÿ˜†

You are right. I was missing the extend-include = ["*.ipynb"] I could swear this worked on my Mac without that at some point ๐Ÿ˜†

Yes, it works without any configuration when using the Python based language server but it doesn't with the native server (ruff.nativeServer: "on"). This has changed with the latest minor release where Jupyter Notebooks are linted and formatted by default: https://astral.sh/blog/ruff-v0.6.0#jupyter-notebooks-are-now-linted-and-formatted-by-default.