-
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
Fallback to kernelspec to check if it's a Python notebook #12875
Conversation
28db6da
to
5bed32f
Compare
crates/ruff_notebook/src/notebook.rs
Outdated
self.raw | ||
.metadata | ||
.language_info | ||
.as_ref() | ||
.map_or(true, |language| language.name == "python") | ||
if let Some(language_info) = self.raw.metadata.language_info.as_ref() { | ||
return language_info.name == "python"; | ||
} | ||
if let Some(kernel_spec) = self.raw.metadata.kernelspec.as_ref() { | ||
return kernel_spec.language.as_deref() == Some("python"); | ||
} | ||
false |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not exactly sure why was the default value true
in case language_info
is absent but that doesn't seem correct to me. If we can't infer the language from either language_info
or kernelspec
, we'll now return false
instead.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, so the notebooks in the ecosystem diff doesn't have both language_info
and kernelspec
in which case we're not marking it as Python notebook. I think I'd need to revert this change to return true
in this case.
|
Need to look at what's going on with the notebooks in ecosystem output. |
5bed32f
to
03d2c0c
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome. Thanks @dhruvmanila for pushing this changes before the release!
Summary
This PR adds a fallback logic for
is_python_notebook
to check thekernelspec.language
field.Reference implementation in VS Code: https://github.com/microsoft/vscode/blob/1c31e758985efe11bc0453a45ea0bb6887e670a4/extensions/ipynb/src/deserializers.ts#L20-L22
It's also required for the kernel to provide the
language
they're implementing based on https://jupyter-client.readthedocs.io/en/stable/kernels.html#kernel-specs reference although that's for thekernel.json
file but is also included in the notebook metadata.Closes: #12281
Test Plan
Add a test case for
is_python_notebook
and include the test notebook for round trip validation.The test notebook contains two cells, one is JavaScript (denoted via the
vscode.languageId
metadata) and the other is Python (no metadata). The notebook metadata only containskernelspec
and thelanguage_info
is absent.I also verified that this is a valid notebook by opening it in Jupyter Lab, VS Code and using
nbformat
validator.