File tree 1 file changed +9
-1
lines changed
1 file changed +9
-1
lines changed Original file line number Diff line number Diff line change @@ -9,6 +9,9 @@ def clean_notebook(file_path):
9
9
10
10
# Clean cells
11
11
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
12
15
if 'outputs' in cell :
13
16
cell ['outputs' ] = []
14
17
if 'execution_count' in cell :
@@ -18,7 +21,12 @@ def clean_notebook(file_path):
18
21
19
22
# Clean notebook metadata
20
23
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
22
30
23
31
with open (file_path , 'w' , encoding = 'utf-8' ) as f :
24
32
nbformat .write (notebook , f )
You can’t perform that action at this time.
0 commit comments