Skip to content

Commit 777a75b

Browse files
committed
update notebook lint config
run both via ruff and nbqa - ruff notebook support doesn't handle namespace rules well with cell magics (F) - nbqa temp files don't handle isort rules well - erroneous success status in ruff check with --fix
1 parent 245fa95 commit 777a75b

8 files changed

+1067
-840
lines changed

.pre-commit-config.yaml

+10
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,28 @@ repos:
1010
- "--fix"
1111
exclude_types:
1212
- jupyter
13+
- id: ruff
14+
name: ruff (notebooks)
15+
args:
16+
- "--fix"
17+
types:
18+
- jupyter
1319
- id: ruff-format
20+
# run via nbqa to handle cell magics
1421
exclude_types:
1522
- jupyter
1623
# run ruff via nbqa, which has better and configurable handling of cell magics
1724
# than ruff itself
25+
# but has trouble with isort rules
1826
- repo: https://github.com/nbQA-dev/nbQA
1927
rev: 1.9.0
2028
hooks:
2129
- id: nbqa-ruff-format
2230
- id: nbqa-ruff-check
2331
args:
2432
- --fix
33+
# isort rules get confused in the temporary files
34+
- --ignore=I
2535
- repo: https://github.com/pre-commit/mirrors-prettier
2636
rev: v4.0.0-alpha.8
2737
hooks:

docs/source/examples/Futures.ipynb

+4-6
Original file line numberDiff line numberDiff line change
@@ -171,9 +171,7 @@
171171
{
172172
"cell_type": "code",
173173
"execution_count": 7,
174-
"metadata": {
175-
"scrolled": true
176-
},
174+
"metadata": {},
177175
"outputs": [
178176
{
179177
"data": {
@@ -416,7 +414,7 @@
416414
},
417415
"outputs": [],
418416
"source": [
419-
"def task(n):\n",
417+
"def interactive_task(n):\n",
420418
" \"\"\"Generates a 1xN array and computes its 2-norm\"\"\"\n",
421419
" import numpy\n",
422420
" from numpy.linalg import norm\n",
@@ -542,8 +540,8 @@
542540
}
543541
],
544542
"source": [
545-
"print(\"Local time:\")\n",
546-
"%time ref = list(map(task, sizes))"
543+
"%%time\n",
544+
"ref = list(map(task, sizes))"
547545
]
548546
},
549547
{

docs/source/examples/Monte Carlo Options.ipynb

+197-76
Large diffs are not rendered by default.

docs/source/examples/Using Dill.ipynb

+83-109
Large diffs are not rendered by default.

docs/source/examples/broadcast/MPI Broadcast.ipynb

+2-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,8 @@
9191
"metadata": {},
9292
"outputs": [],
9393
"source": [
94-
"%px from mpi4py.MPI import COMM_WORLD as MPI"
94+
"%%px\n",
95+
"from mpi4py.MPI import COMM_WORLD as MPI"
9596
]
9697
},
9798
{

docs/source/examples/dask.ipynb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1024,7 +1024,7 @@
10241024
],
10251025
"source": [
10261026
"%%px\n",
1027-
"dask_worker.data"
1027+
"dask_worker.data # noqa"
10281028
]
10291029
},
10301030
{
@@ -1052,7 +1052,7 @@
10521052
"name": "python",
10531053
"nbconvert_exporter": "python",
10541054
"pygments_lexer": "ipython3",
1055-
"version": "3.9.6"
1055+
"version": "3.11.9"
10561056
},
10571057
"widgets": {
10581058
"application/vnd.jupyter.widget-state+json": {

0 commit comments

Comments
 (0)