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