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

Broken jupyter notebook cell formatting. #617

Closed
gabethehuman opened this issue Sep 17, 2024 · 2 comments · Fixed by astral-sh/ruff-lsp#496
Closed

Broken jupyter notebook cell formatting. #617

gabethehuman opened this issue Sep 17, 2024 · 2 comments · Fixed by astral-sh/ruff-lsp#496

Comments

@gabethehuman
Copy link

gabethehuman commented Sep 17, 2024

Hello.

Ever since ruff v2024.40.0 jupyter notebook cells are not being formatted, neither on on save nor manually. I use the latest VS Code (as of September 17th 2024) and latest ruff, although I noticed that v2024.40.0 was the last version for which it worked.

Settings:

  // jupyter
  "jupyter.askForKernelRestart": false,
  "notebook.consolidatedRunButton": true,
  "notebook.formatOnSave.enabled": true,
  "notebook.defaultFormatter": "charliermarsh.ruff",

  // ruff
  "ruff.enable": true,
  "ruff.organizeImports": true,
  "ruff.importStrategy": "useBundled",
  "ruff.format.args": ["--line-length=120"],
  "ruff.lint.run": "onSave",
  "ruff.lint.args": [
      "--line-length=120",
      "--ignore=ANN101,ANN204,ANN401,C408,D,EM101,EM102,ERA001,FA100,FA102,INP001,N812,NPY002,PLR0402,PLR0913,PTH123,RET504,S101,S311,S603,S607,SIM118,T201,TRY002,TRY003,TRY300",
      "--select=ALL,D102,D103,D106,D207,D208,D214,D215,D300,D301,D417,D418,D419",
  ],

  // python linter and formatter
  "[python]": {
      "editor.formatOnSave": true,
      "editor.defaultFormatter": "charliermarsh.ruff",
      "editor.codeActionsOnSave": {
          "source.fixAll": "never",
          "source.organizeImports": "explicit"
      }
  },
@MichaReiser
Copy link
Member

I'm a bit confused. Is v2024.40.0 the last version for which formatting did work or the version when it stopped working? If 2024.40.0 was the last version where it worked, then I suspect that we broke ruff-lsp when we promoted notebooks to be enabled by default.

@MichaReiser
Copy link
Member

Okay, I think I see the issue.

Formatting a notebook with ruff-lsp gives me:

[crates/ruff/src/commands/format_stdin.rs:72:11] format_source_code(path, cli.range, settings, source_type, mode) = Err(
    Read(
        Some(
            "/home/micha/astral/test/src/test-notebook.ipynb",
        ),
        Notebook(
            InvalidSchema(
                Error("invalid type: null, expected struct CellMetadata", line: 1, column: 283),
            ),
        ),
    ),
)

So it seems that ruff lsp doesn't send a notebook with a cell.metadata field but the field is required according to the notebook specification

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

Successfully merging a pull request may close this issue.

2 participants