Skip to content

Support formatting jupyter notebooks #1218

@konstin

Description

@konstin

black supports formatting jupyter notebook with the jupyter extra black[jupyter]. If installed like this, it formats jupyter notebooks just like python files. It would be nice if ruff could similarly lint and fix jupyter notebooks.

Steps to implement this:

  • Read Jupyter notebooks, build a mapping between cells and concatenated code and and print lint errors with cell ids. The code is in jupyter/notebooks.rs.
  • Apply fixes to concatenated code and map back to cells
  • Write back jupyter notebooks ensuring that if there are no changes the json is identical (roundtrip support). You might need to extend or replace the current schema or drop some of the schema for just serde_json::Value. See also the black implementation.
  • Test roundtrip support with a bunch of different notebooks found in the wild, ideally from different generators (e.g. jupyter notebook and pycharm) and different schema versions.
  • Remove jupyter_notebook feature and include .ipynb files in ruff by default
  • Optional: Check if there a any lints that should be off for jupyter notebook, e.g. "no print" or isort rules might not make sense

Metadata

Metadata

Assignees

Labels

coreRelated to core functionalityhelp wantedContributions especially welcome

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions