Skip to content

Commit eb04ab0

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 35357e1 commit eb04ab0

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: .github/workflows/lint.py

+9-1
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ 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 ('quiz' in cell['metadata']['tags'] or 'noclean' in cell['metadata']['tags']):
14+
continue
1215
if 'outputs' in cell:
1316
cell['outputs'] = []
1417
if 'execution_count' in cell:
@@ -18,7 +21,12 @@ def clean_notebook(file_path):
1821

1922
# Clean notebook metadata
2023
if 'metadata' in notebook:
21-
notebook['metadata'] = {}
24+
new_metadata = {}
25+
if 'language_info' in notebook['metadata']:
26+
new_metadata['language_info'] = notebook['metadata']['language_info']
27+
if 'kernelspec' in notebook['metadata']:
28+
new_metadata['kernelspec'] = notebook['metadata']['kernelspec']
29+
notebook['metadata'] = new_metadata
2230

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

0 commit comments

Comments
 (0)