Skip to content

Commit 13ba4b1

Browse files
committed
added ability to not clean cells with tags of quiz or noclean. Keep kernelspec and language_info metadata for notebook
1 parent 27d8739 commit 13ba4b1

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

Diff for: .github/workflows/lint.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ def clean_notebook(file_path):
99

1010
# Clean cells
1111
for cell in notebook.cells:
12+
# skip cells with a quiz or no clean tag
13+
if 'metadata' in cell and 'tags' in cell['metadata'] and (
14+
'quiz' in cell['metadata']['tags'] or 'noclean' in cell['metadata']['tags']):
15+
continue
1216
if 'outputs' in cell:
1317
cell['outputs'] = []
1418
if 'execution_count' in cell:
@@ -18,7 +22,12 @@ def clean_notebook(file_path):
1822

1923
# Clean notebook metadata
2024
if 'metadata' in notebook:
21-
notebook['metadata'] = {}
25+
new_metadata = {}
26+
if 'language_info' in notebook['metadata']:
27+
new_metadata['language_info'] = notebook['metadata']['language_info']
28+
if 'kernelspec' in notebook['metadata']:
29+
new_metadata['kernelspec'] = notebook['metadata']['kernelspec']
30+
notebook['metadata'] = new_metadata
2231

2332
with open(file_path, 'w', encoding='utf-8') as f:
2433
nbformat.write(notebook, f)

0 commit comments

Comments
 (0)