-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Enable formatting for Jupyter notebooks (#7749)
## Summary This PR enables `ruff format` to format Jupyter notebooks. Most of the work is contained in a new `format_source` method that formats a generic `SourceKind`, then returns `Some(transformed)` if the source required formatting, or `None` otherwise. Closes #7598. ## Test Plan Ran `cat foo.py | cargo run -p ruff_cli -- format --stdin-filename Untitled.ipynb`; verified that the console showed a reasonable error: ```console warning: Failed to read notebook Untitled.ipynb: Expected a Jupyter Notebook, which must be internally stored as JSON, but this file isn't valid JSON: EOF while parsing a value at line 1 column 0 ``` Ran `cat Untitled.ipynb | cargo run -p ruff_cli -- format --stdin-filename Untitled.ipynb`; verified that the JSON output contained formatted source code.
- Loading branch information
1 parent
0961f00
commit bdf2852
Showing
7 changed files
with
419 additions
and
161 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.