Skip to content

Commit a58ee12

Browse files
committed
Add pre-commit check for notebook metadata
1 parent c6dc81c commit a58ee12

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ The CI pipeline in this repo runs a bunch of validation checks and code reformat
7777
You will need to develop your notebooks using Python 3.11 or higher. By default, Notebooks developed on SingleStore will be using this version of Python. This is required for the pre-commit checks to run:
7878

7979
```bash
80-
pip3 install pre-commit
80+
pip3 install pre-commit==3.7.1
8181
pre-commit install
8282
```
8383

resources/nb-check.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,34 @@
1010
from typing import List
1111

1212

13+
DEFAULT_NOTEBOOK_METADATA = {
14+
'metadata': {
15+
'jupyterlab': {
16+
'notebooks': {
17+
'version_major': 6,
18+
'version_minor': 4,
19+
},
20+
},
21+
'kernelspec': {
22+
'display_name': 'Python 3 (ipykernel)',
23+
'language': 'python',
24+
'name': 'python3',
25+
},
26+
'language_info': {
27+
'codemirror_mode': {
28+
'name': 'ipython',
29+
'version': 3,
30+
},
31+
'file_extension': '.py',
32+
'mimetype': 'text/x-python',
33+
'name': 'python',
34+
'nbconvert_exporter': 'python',
35+
'pygments_lexer': 'ipython3',
36+
'version': '3.11.6',
37+
},
38+
},
39+
}
40+
1341
NOTEBOOK_HEADER = [
1442
'<div id="singlestore-header" style="display: flex; background-color: {background_color}; padding: 5px;">\n',
1543
' <div id="icon-image" style="width: 90px; height: 90px;">\n',
@@ -137,12 +165,15 @@ def new_markdown_cell(cell_id: str, content: list[str]) -> dict[str, Any]:
137165
error(f'notebook must be named `notebook.ipynb`: {f}')
138166

139167
# Clear out SingleStore metadata
140-
metadata = nb.get('metadata', {})
168+
metadata = nb.get('metadata', DEFAULT_NOTEBOOK_METADATA)
141169

142170
for k in list(metadata.keys()):
143171
if k.startswith('singlestore'):
144172
del metadata[k]
145173

174+
# Make sure notebook has a metadata field
175+
nb['metadata'] = metadata
176+
146177
cells = nb.get('cells', [])
147178

148179
# Remove metadata

0 commit comments

Comments
 (0)