-
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.
Detect and ignore Jupyter automagics (#8398)
## Summary LangChain is attempting to use Ruff over their Jupyter notebooks (https://github.com/langchain-ai/langchain/pull/12677/files), but running into a bunch of syntax errors, the majority of which come from our inability to recognize automagic. If you run this in a cell: ```jupyter pip install requests ``` Jupyter will automatically treat that as: ```jupyter %pip install requests ``` We need to ignore cells that use these automagics, since the parser doesn't understand them. (I guess we could support it in the parser, but that seems much harder?). The good news is that AFAICT Jupyter doesn't let you mix automagics with code, so by skipping these cells, we don't miss out on analyzing any Python code. ## Test Plan 1. `cargo test` 2. Ran over LangChain and verified that there are no more errors relating to `pip install` automagics.
- Loading branch information
1 parent
2ff1afb
commit f64c389
Showing
5 changed files
with
154 additions
and
6 deletions.
There are no files selected for viewing
8 changes: 8 additions & 0 deletions
8
crates/ruff_notebook/resources/test/fixtures/jupyter/cell/automagic.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"execution_count": null, | ||
"cell_type": "code", | ||
"id": "1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": ["pip install requests"] | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/ruff_notebook/resources/test/fixtures/jupyter/cell/automagic_after_code.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"execution_count": null, | ||
"cell_type": "code", | ||
"id": "1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": ["x = 1\n", "pip install requests"] | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/ruff_notebook/resources/test/fixtures/jupyter/cell/automagic_before_code.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"execution_count": null, | ||
"cell_type": "code", | ||
"id": "1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": ["pip install requests\n", "x = 1"] | ||
} |
8 changes: 8 additions & 0 deletions
8
crates/ruff_notebook/resources/test/fixtures/jupyter/cell/automagics.json
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"execution_count": null, | ||
"cell_type": "code", | ||
"id": "1", | ||
"metadata": {}, | ||
"outputs": [], | ||
"source": ["pip install requests\n", "pip install requests"] | ||
} |
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