Skip to content

Commit 4e1228d

Browse files
committed
Remove outputs when packaging samples
1 parent 9a53f0f commit 4e1228d

File tree

1 file changed

+17
-1
lines changed

1 file changed

+17
-1
lines changed

resources/package-samples.py

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,28 @@
11
#!/usr/bin/env python3
22
"""Package sample notebooks for use in the managed service portal."""
33
import argparse
4+
import json
45
import os
56
import sys
67
import tomllib
78
from zipfile import ZipFile
89

910

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+
1026
if __name__ == '__main__':
1127

1228
parser = argparse.ArgumentParser(
@@ -74,4 +90,4 @@
7490
with ZipFile(args.outfile, 'w') as out:
7591
for path, name in files:
7692
print(path, ' => ', name)
77-
out.write(path, arcname=name)
93+
out.writestr(name, clear_outputs(path))

0 commit comments

Comments
 (0)