Skip to content

Commit 6687d66

Browse files
committed
Tests: Normalize notebok metadata and add tests for notebook formats and metadata.
1 parent a076d2a commit 6687d66

File tree

121 files changed

+6790
-10817
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

121 files changed

+6790
-10817
lines changed
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
name: PR Comment on Notebook Format Check
2+
3+
on:
4+
workflow_run:
5+
workflows: ["Test Notebook Format"]
6+
types: [completed]
7+
8+
# Write permissions for commenting
9+
permissions:
10+
pull-requests: write
11+
12+
jobs:
13+
comment:
14+
runs-on: ubuntu-latest
15+
if: github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.conclusion == 'failure'
16+
17+
steps:
18+
- name: Download PR comment data
19+
uses: actions/download-artifact@v4
20+
with:
21+
name: pr-comment-data
22+
github-token: ${{ secrets.GITHUB_TOKEN }}
23+
run-id: ${{ github.event.workflow_run.id }}
24+
25+
- name: Post comment on PR
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const fs = require('fs');
30+
31+
// Read PR number from artifact
32+
const prNumber = parseInt(fs.readFileSync('pr_number', 'utf8').trim());
33+
34+
if (!prNumber || isNaN(prNumber)) {
35+
console.log('No valid PR number found, skipping comment.');
36+
return;
37+
}
38+
39+
const runUrl = `${process.env.GITHUB_SERVER_URL}/${process.env.GITHUB_REPOSITORY}/actions/runs/${{ github.event.workflow_run.id }}`;
40+
41+
const commentBody = `## ❌ Notebook Format Check Failed
42+
43+
**One or more Jupyter notebooks have format or metadata issues.**
44+
45+
Please check the [workflow run logs](${runUrl}) for details on which notebooks have issues.
46+
47+
### What is checked:
48+
49+
1. **Schema integrity** — notebooks must be valid according to the Jupyter notebook JSON schema
50+
2. **Metadata conformance** — notebooks must have the standard metadata block (accelerator, colab, kernelspec, language_info)
51+
3. **Clean outputs** — non-SOLUTION notebooks must have outputs, execution counts, and execution timing metadata cleared
52+
53+
### How to fix:
54+
55+
\`\`\`bash
56+
# Check all tutorials
57+
python3 brev/test-notebook-format.py
58+
59+
# Check a specific tutorial
60+
python3 brev/test-notebook-format.py <tutorial-name>
61+
62+
# Auto-fix all issues
63+
python3 brev/test-notebook-format.py --fix
64+
65+
# Auto-fix a specific tutorial
66+
python3 brev/test-notebook-format.py <tutorial-name> --fix
67+
\`\`\`
68+
`;
69+
70+
// Check if we already commented on this PR to avoid spam
71+
const { data: comments } = await github.rest.issues.listComments({
72+
owner: context.repo.owner,
73+
repo: context.repo.repo,
74+
issue_number: prNumber
75+
});
76+
77+
const botComment = comments.find(comment =>
78+
comment.user.type === 'Bot' &&
79+
comment.body.includes('Notebook Format Check Failed')
80+
);
81+
82+
if (botComment) {
83+
// Update existing comment
84+
await github.rest.issues.updateComment({
85+
owner: context.repo.owner,
86+
repo: context.repo.repo,
87+
comment_id: botComment.id,
88+
body: commentBody
89+
});
90+
console.log(`Updated existing comment on PR #${prNumber}`);
91+
} else {
92+
// Create new comment
93+
await github.rest.issues.createComment({
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
issue_number: prNumber,
97+
body: commentBody
98+
});
99+
console.log(`Created comment on PR #${prNumber}`);
100+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
name: Test Notebook Format
2+
3+
on:
4+
push:
5+
branches:
6+
- '**'
7+
pull_request:
8+
types: [opened, reopened, synchronize]
9+
10+
# Minimal permissions - only read access needed for checks
11+
permissions:
12+
contents: read
13+
14+
jobs:
15+
test-notebook-format:
16+
runs-on: ubuntu-latest
17+
18+
steps:
19+
- name: Checkout repository
20+
uses: actions/checkout@v4
21+
22+
- name: Set up Python
23+
uses: actions/setup-python@v5
24+
with:
25+
python-version: '3.13'
26+
27+
- name: Install nbformat
28+
run: pip install nbformat
29+
30+
- name: Check notebook format
31+
id: notebook-format-check
32+
run: python3 brev/test-notebook-format.py
33+
34+
- name: Save PR number and result
35+
if: always() && github.event_name == 'pull_request'
36+
run: |
37+
mkdir -p ./pr-comment-data
38+
echo '${{ github.event.pull_request.number }}' > ./pr-comment-data/pr_number
39+
echo '${{ steps.notebook-format-check.outcome }}' > ./pr-comment-data/outcome
40+
41+
- name: Upload PR comment data
42+
if: always() && github.event_name == 'pull_request'
43+
uses: actions/upload-artifact@v4
44+
with:
45+
name: pr-comment-data
46+
path: pr-comment-data/
47+
retention-days: 1

Accelerated_Python_User_Guide/notebooks/Chapter_01_GPU_Computing_Basics.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,12 @@
222222
}
223223
],
224224
"metadata": {
225+
"accelerator": "GPU",
226+
"colab": {
227+
"gpuType": "T4",
228+
"provenance": [],
229+
"toc_visible": true
230+
},
225231
"kernelspec": {
226232
"display_name": "Python 3 (ipykernel)",
227233
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_02_Brief_Intro_to_CUDA.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,12 @@
124124
}
125125
],
126126
"metadata": {
127+
"accelerator": "GPU",
128+
"colab": {
129+
"gpuType": "T4",
130+
"provenance": [],
131+
"toc_visible": true
132+
},
127133
"kernelspec": {
128134
"display_name": "Python 3 (ipykernel)",
129135
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_03_Python_on_the_GPU.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,12 @@
8585
}
8686
],
8787
"metadata": {
88+
"accelerator": "GPU",
89+
"colab": {
90+
"gpuType": "T4",
91+
"provenance": [],
92+
"toc_visible": true
93+
},
8894
"kernelspec": {
8995
"display_name": "Python 3 (ipykernel)",
9096
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_04_Scientific_Computing_with_CuPy.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,12 @@
360360
}
361361
],
362362
"metadata": {
363+
"accelerator": "GPU",
364+
"colab": {
365+
"gpuType": "T4",
366+
"provenance": [],
367+
"toc_visible": true
368+
},
363369
"kernelspec": {
364370
"display_name": "Python 3 (ipykernel)",
365371
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_05_CUDA_Kernels_with_Numba.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,12 @@
306306
}
307307
],
308308
"metadata": {
309+
"accelerator": "GPU",
310+
"colab": {
311+
"gpuType": "T4",
312+
"provenance": [],
313+
"toc_visible": true
314+
},
309315
"kernelspec": {
310316
"display_name": "Python 3 (ipykernel)",
311317
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_06_Intro_to_nvmath-python.ipynb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,14 @@
492492
}
493493
],
494494
"metadata": {
495+
"accelerator": "GPU",
496+
"colab": {
497+
"gpuType": "T4",
498+
"provenance": [],
499+
"toc_visible": true
500+
},
495501
"kernelspec": {
496-
"display_name": ".venv",
502+
"display_name": "Python 3 (ipykernel)",
497503
"language": "python",
498504
"name": "python3"
499505
},
@@ -507,7 +513,7 @@
507513
"name": "python",
508514
"nbconvert_exporter": "python",
509515
"pygments_lexer": "ipython3",
510-
"version": "3.10.12"
516+
"version": "3.11.7"
511517
}
512518
},
513519
"nbformat": 4,

Accelerated_Python_User_Guide/notebooks/Chapter_07_Intro_to_cuDF.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,12 @@
335335
}
336336
],
337337
"metadata": {
338+
"accelerator": "GPU",
339+
"colab": {
340+
"gpuType": "T4",
341+
"provenance": [],
342+
"toc_visible": true
343+
},
338344
"kernelspec": {
339345
"display_name": "Python 3 (ipykernel)",
340346
"language": "python",

Accelerated_Python_User_Guide/notebooks/Chapter_08_Intro_to_cuML.ipynb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,12 @@
436436
}
437437
],
438438
"metadata": {
439+
"accelerator": "GPU",
440+
"colab": {
441+
"gpuType": "T4",
442+
"provenance": [],
443+
"toc_visible": true
444+
},
439445
"kernelspec": {
440446
"display_name": "Python 3 (ipykernel)",
441447
"language": "python",

0 commit comments

Comments
 (0)