File tree Expand file tree Collapse file tree 1 file changed +10
-1
lines changed
Expand file tree Collapse file tree 1 file changed +10
-1
lines changed Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments