Skip to content

Commit 1d11c82

Browse files
committed
also strip empty cells (didn't have any, apparently)
1 parent 07d77b3 commit 1d11c82

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

scripts/nblint.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,12 @@ def nblint():
3030
nb_text = nb_path.read_text()
3131
nb_node = nbformat.reads(nb_text, 4)
3232
changes = 0
33+
has_empty = 0
3334
for cell in nb_node.cells:
3435
cell_type = cell["cell_type"]
3536
source = "".join(cell["source"])
37+
if not source.strip():
38+
has_empty += 1
3639
if cell_type == "markdown":
3740
prettier = subprocess.Popen(
3841
[
@@ -63,6 +66,13 @@ def nblint():
6366
if new != source:
6467
cell["source"] = new.splitlines(True)
6568
changes += 1
69+
70+
if has_empty:
71+
changes += 1
72+
nb_node.cells = [
73+
cell for cell in nb_node.cells if "".join(cell["source"]).strip()
74+
]
75+
6676
if changes:
6777
with nb_path.open("w") as fpt:
6878
nbformat.write(nb_node, fpt)

0 commit comments

Comments
 (0)