-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Complete Jupyter notebook integration #5188
Comments
My main question would be: at what point do you think we can remove the feature flag, and open this up to users? (Maybe we're already past that point!) |
I do think we're ready except that without the (1) task above Ruff might give false positives. Without that we would ignore any cell which contains magic commands. Now, we would also ignore if it contains valid Python code. It could be that a variable is defined in that cell and is being referenced in another cell. Here, we might trigger undefined variable. Similar example can be given for imports. I see this a lot for |
What do you think about releasing this under experimental? I'm not sure what would that look like but maybe we don't add the |
Yeah, I think it would be reasonable to release it now (even without magic handling) and omit We should also add the magic command support, but doesn't have to block if it's opt-in :) |
(To be explicit: we could just remove the flag now.) |
## Summary Experimental release for Jupyter Notebook integration. Currently, this requires a user to explicitly opt-in using the [include](https://beta.ruff.rs/docs/settings/#include) configuration: ```toml [tool.ruff] include = ["*.py", "*.pyi", "**/pyproject.toml", "*.ipynb"] ``` Or, a user can pass in the file directly: ```sh ruff check path/to/notebook.ipynb ``` For known limitations, please refer #5188 ## Test Plan Following command should work without the `--all-features` flag: ```sh cargo dev round-trip /path/to/notebook.ipynb ``` Following command should work with the above config file along with `select = ["ALL"]`: ```sh cargo run --bin ruff -- check --no-cache --config=../test-repos/openai-cookbook/pyproject.toml --fix ../test-repos/openai-cookbook/ ``` Passing the Jupyter notebook directly: ```sh cargo run --bin ruff -- check --no-cache --isolated --select=ALL --fix ../test-repos/openai-cookbook/examples/Classification_using_embeddings.ipynb ```
I'm not sure if this deserves its own issue, but: Would it be possible to use My users typically edit notebooks in Google Colab. Google Colab uses two-space indentation in the ipynb file, instead of the typical one-space indentation. Google Colab also puts keys like metadata, nbformat, nbformat_minor at the top of the file, but I would love to be able to opt out of ipynb formatting, so that only the Python code inside cells is reformatted. |
(I think it deserves its own issue, we can discuss it there :)) |
Closing this as completed. The only thing remaining is to support |
Meta issue to keep track of the remaining tasks before shipping Jupyter notebook native integration:
--diff
support for Jupyter notebooks #4727--add-noqa
support for Jupyter notebooks #5189black
for Jupyter notebooks #5190Formatter Support
Add support forIpyEscapeCommand
token inSimpleTokenizer
(if required)StmtIpyEscapeCommand
ExprIpyEscapeCommand
Editor Integrations
ruff-lsp
so that other editors can benefit as well.IPython Syntax Handling (
%
,!
, etc.)Ruff
Jupyter
mode while parsing Notebook source code #6090Proposed new rules
%
) (Autofix: remove the statement)% matplotlib inline
) (Autofix: remove all the whitespaces) (Only valid for%
magic prefix)Existing rule changes
F481
autofix for Jupyter line magic expr #6116I'll be looking at other related rules and update this issue accordingly
Parser
Mode::Jupyter
RustPython-Parser#23Autofix for Jupyter Notebook
Implementation
The text was updated successfully, but these errors were encountered: