File tree Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Expand file tree Collapse file tree 1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change 1
1
#!/usr/bin/env python3
2
2
"""Package sample notebooks for use in the managed service portal."""
3
3
import argparse
4
+ import json
4
5
import os
5
6
import sys
6
7
import tomllib
7
8
from zipfile import ZipFile
8
9
9
10
11
+ def clear_outputs (path : str ) -> str :
12
+ """Remove outputs from notebook at path."""
13
+ with open (path , 'r' ) as infile :
14
+ nb = json .loads (infile .read ())
15
+ for cell in nb ['cells' ]:
16
+ if 'metadata' in cell :
17
+ cell ['metadata' ]['execution' ] = {}
18
+ if 'outputs' in cell :
19
+ cell ['outputs' ] = []
20
+ if 'metadata' in nb :
21
+ if 'singlestore_connection' in nb ['metadata' ]:
22
+ nb ['metadata' ]['singlestore_connection' ] = {}
23
+ return json .dumps (nb , indent = 2 )
24
+
25
+
10
26
if __name__ == '__main__' :
11
27
12
28
parser = argparse .ArgumentParser (
74
90
with ZipFile (args .outfile , 'w' ) as out :
75
91
for path , name in files :
76
92
print (path , ' => ' , name )
77
- out .write ( path , arcname = name )
93
+ out .writestr ( name , clear_outputs ( path ) )
You can’t perform that action at this time.
0 commit comments