Skip to content

Commit 16470d7

Browse files
authored
Fix multiple empty cells (#30)
1 parent 1de7eb2 commit 16470d7

7 files changed

Lines changed: 104 additions & 6 deletions

File tree

.github/workflows/test.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
fail-fast: false
2222
matrix:
2323
os: [ubuntu-latest, macos-latest, windows-latest]
24-
python-version: ['3.8', '3.9', '3.10', '3.11']
24+
python-version: ['3.8', '3.9', '3.10', '3.11', 3.12-dev]
2525
timeout-minutes: 10
2626
steps:
2727
- uses: actions/checkout@v3
@@ -31,4 +31,8 @@ jobs:
3131
- name: Install hatch
3232
run: pipx install hatch
3333
- name: Testing
34+
if: matrix.python-version != '3.12-dev'
3435
run: hatch run +py=${{ matrix.python-version }} test:run
36+
- name: Testing 3.12-dev
37+
if: matrix.python-version == '3.12-dev'
38+
run: hatch run +py=3.12 test:run

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ repos:
55
hooks:
66
- id: black
77
- repo: https://github.com/pre-commit/mirrors-mypy
8-
rev: v1.4.1
8+
rev: v1.5.1
99
hooks:
1010
- id: mypy
1111
- repo: https://github.com/astral-sh/ruff-pre-commit
12-
rev: v0.0.278
12+
rev: v0.0.285
1313
hooks:
1414
- id: ruff
1515
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ scripts.update = "pre-commit autoupdate"
4242
[tool.hatch.envs.test]
4343
dependencies = ["pytest"]
4444
scripts.run = "pytest tests"
45-
matrix = [{ python = ["3.8", "3.9", "3.10", "3.11"] }]
45+
matrix = [{ python = ["3.8", "3.9", "3.10", "3.11", "3.12"] }]
4646

4747
[tool.hatch.build]
4848
sources = ["src"]

src/clean_notebook/clean.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def clean_single_notebook(
4343
nb = json.loads(raw)
4444

4545
cleaned = False
46-
for cell in nb["cells"]:
46+
for cell in nb["cells"].copy():
4747
cleaned |= _update_value(cell, "outputs", [])
4848
cleaned |= _update_value(cell, "execution_count", None)
4949
cleaned |= _update_value(cell, "metadata", _ignore(cell, ignore))
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "9259e103-a9fe-4be1-8204-dfe194e8e978",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"a = 2"
11+
]
12+
}
13+
],
14+
"metadata": {
15+
"language_info": {
16+
"name": "python",
17+
"pygments_lexer": "ipython3"
18+
}
19+
},
20+
"nbformat": 4,
21+
"nbformat_minor": 5
22+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": null,
6+
"id": "9259e103-a9fe-4be1-8204-dfe194e8e978",
7+
"metadata": {},
8+
"outputs": [],
9+
"source": [
10+
"a = 2"
11+
]
12+
},
13+
{
14+
"cell_type": "code",
15+
"execution_count": null,
16+
"id": "5d06a671-1c6f-44b1-ad7b-ba26aaa020a2",
17+
"metadata": {},
18+
"outputs": [],
19+
"source": []
20+
},
21+
{
22+
"cell_type": "code",
23+
"execution_count": null,
24+
"id": "3a4c8839",
25+
"metadata": {},
26+
"outputs": [],
27+
"source": []
28+
},
29+
{
30+
"cell_type": "code",
31+
"execution_count": null,
32+
"id": "c08052ad",
33+
"metadata": {},
34+
"outputs": [],
35+
"source": []
36+
},
37+
{
38+
"cell_type": "code",
39+
"execution_count": null,
40+
"id": "50aad535",
41+
"metadata": {},
42+
"outputs": [],
43+
"source": []
44+
}
45+
],
46+
"metadata": {
47+
"kernelspec": {
48+
"display_name": "base",
49+
"language": "python",
50+
"name": "python3"
51+
},
52+
"language_info": {
53+
"codemirror_mode": {
54+
"name": "ipython",
55+
"version": 3
56+
},
57+
"file_extension": ".py",
58+
"mimetype": "text/x-python",
59+
"name": "python",
60+
"nbconvert_exporter": "python",
61+
"pygments_lexer": "ipython3",
62+
"version": "3.10.9"
63+
},
64+
"vscode": {
65+
"interpreter": {
66+
"hash": "5d4a37d74e2201ea12a12f96f8b5fbedd7b0b271dbcea21af2b23b61569be5db"
67+
}
68+
}
69+
},
70+
"nbformat": 4,
71+
"nbformat_minor": 5
72+
}

tests/test_clean_notebook.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ def temp_path(tmp_path_factory: TempPathFactory) -> Iterator[Path]:
3131
rmtree(dst)
3232

3333

34-
TESTS = ["ascii", "jupyterlab", "vscode", "colab", "empty_cell"]
34+
TESTS = ["ascii", "jupyterlab", "vscode", "colab", "empty_cell", "empty_multi_cell"]
3535

3636

3737
@pytest.mark.parametrize("test", [*TESTS, "ignore_slideshow"])

0 commit comments

Comments
 (0)