Skip to content

Commit 2eb8ca3

Browse files
committed
WIP: fixing broken v3.
1 parent f5c6f0c commit 2eb8ca3

File tree

1 file changed

+19
-7
lines changed

1 file changed

+19
-7
lines changed

tools/convert_nbformat.py

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,24 @@ def iter_recipes(root, dir):
2727
curdir = op.realpath(op.dirname(os.path.abspath(__file__)))
2828
root = op.realpath(op.join(curdir, '../notebooks'))
2929

30+
31+
def fix_v3(path):
32+
with open(path, 'r') as f:
33+
nb = json.load(f)
34+
35+
for cell in nb['worksheets'][0]['cells']:
36+
if isinstance(cell.get('metadata', {}), list):
37+
cell['metadata'] = {}
38+
39+
with open(path, 'w') as f:
40+
json.dump(f, nb)
41+
42+
43+
3044
def convert_to_v4(path):
3145
nb = read(path, 3)
3246
nb_new = convert(nb, 4)
3347

34-
for cell in nb_new['cells']:
35-
if cell.get('metadata', {}) == []:
36-
cell['metadata'] = {}
37-
3848
nb_new["metadata"] ={
3949
"kernelspec": {
4050
"display_name": "Python 3",
@@ -55,8 +65,8 @@ def convert_to_v4(path):
5565
}
5666
}
5767

58-
validate(nb_new)
59-
write(nb_new, path)
68+
# validate(nb_new)
69+
# write(nb_new, path)
6070

6171
if __name__ == '__main__':
6272

@@ -69,4 +79,6 @@ def convert_to_v4(path):
6979
'03_numpy.ipynb',):
7080
continue
7181
print("converting", file)
72-
convert_to_v4(file)
82+
83+
fix_v3(file)
84+
# convert_to_v4(file)

0 commit comments

Comments
 (0)