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

Consider VS Code cell metadata to determine valid code cells #12864

Merged
merged 2 commits into from
Aug 13, 2024

Conversation

dhruvmanila
Copy link
Member

@dhruvmanila dhruvmanila commented Aug 13, 2024

Summary

This PR adds support for VS Code specific cell metadata to consider when collecting valid code cells.

For context, Ruff only runs on valid code cells. These are the code cells that doesn't contain cell magics. Previously, Ruff only used the notebook's metadata to determine whether it's a Python notebook. But, in VS Code, a notebook's preferred language might be Python but it could still contain code cells for other languages. This can be determined with the metadata.vscode.languageId field.

References:

This brings us one step closer to fixing #12281.

Test Plan

Add test cases for is_valid_python_code_cell and an integration test case which showcase running it end to end. The test notebook contains a JavaScript code cell and a Python code cell.

@dhruvmanila dhruvmanila added the notebook Related to (Jupyter) notebooks label Aug 13, 2024
@dhruvmanila dhruvmanila force-pushed the dhruv/vscode-language-id branch from 8e977dd to 11c222c Compare August 13, 2024 15:55
Copy link
Member

@MichaReiser MichaReiser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thank you.

I think it would be good to add a round-trip test case with additional CellMetadata.

crates/ruff_notebook/src/schema.rs Outdated Show resolved Hide resolved
Copy link

codspeed-hq bot commented Aug 13, 2024

CodSpeed Performance Report

Merging #12864 will degrade performances by 4.09%

Comparing dhruv/vscode-language-id (142de81) with main (899a523)

Summary

⚡ 1 improvements
❌ 1 regressions
✅ 30 untouched benchmarks

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Benchmarks breakdown

Benchmark main dhruv/vscode-language-id Change
linter/all-rules[numpy/globals.py] 765 µs 726.4 µs +5.31%
linter/default-rules[pydantic/types.py] 1.8 ms 1.9 ms -4.09%

Copy link
Contributor

github-actions bot commented Aug 13, 2024

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

@dhruvmanila
Copy link
Member Author

dhruvmanila commented Aug 13, 2024

Added a simple roundtrip test case with additional cell metadata. I also tested it using ruff_dev round-trip notebooks/test.ipynb where the cell metadata isn't sorted and the output gives sorted metadata with all information intact.

@dhruvmanila dhruvmanila merged commit ff53db3 into main Aug 13, 2024
19 of 20 checks passed
@dhruvmanila dhruvmanila deleted the dhruv/vscode-language-id branch August 13, 2024 16:39
dhruvmanila added a commit that referenced this pull request Aug 14, 2024
## Summary

Follow-up to #12864, we don't need to exclude these notebooks anymore.

## Test plan

- [x] Make sure that ecosystem checks are green.
dhruvmanila added a commit to astral-sh/ruff-lsp that referenced this pull request Sep 3, 2024
## Summary

Related to astral-sh/ruff#12864, the cell
metadata is actually a required field. We got away with it previously
because Ruff used `Value`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
notebook Related to (Jupyter) notebooks
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants