Skip to content

Commit

Permalink
Fix multiple empty cells (#30)
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxbro authored Aug 22, 2023
1 parent 1de7eb2 commit 16470d7
Show file tree
Hide file tree
Showing 7 changed files with 104 additions and 6 deletions.
6 changes: 5 additions & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest, windows-latest]
python-version: ['3.8', '3.9', '3.10', '3.11']
python-version: ['3.8', '3.9', '3.10', '3.11', 3.12-dev]
timeout-minutes: 10
steps:
- uses: actions/checkout@v3
Expand All @@ -31,4 +31,8 @@ jobs:
- name: Install hatch
run: pipx install hatch
- name: Testing
if: matrix.python-version != '3.12-dev'
run: hatch run +py=${{ matrix.python-version }} test:run
- name: Testing 3.12-dev
if: matrix.python-version == '3.12-dev'
run: hatch run +py=3.12 test:run
4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ repos:
hooks:
- id: black
- repo: https://github.com/pre-commit/mirrors-mypy
rev: v1.4.1
rev: v1.5.1
hooks:
- id: mypy
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.0.278
rev: v0.0.285
hooks:
- id: ruff
- repo: https://github.com/macisamuele/language-formatters-pre-commit-hooks
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ scripts.update = "pre-commit autoupdate"
[tool.hatch.envs.test]
dependencies = ["pytest"]
scripts.run = "pytest tests"
matrix = [{ python = ["3.8", "3.9", "3.10", "3.11"] }]
matrix = [{ python = ["3.8", "3.9", "3.10", "3.11", "3.12"] }]

[tool.hatch.build]
sources = ["src"]
Expand Down
2 changes: 1 addition & 1 deletion src/clean_notebook/clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def clean_single_notebook(
nb = json.loads(raw)

cleaned = False
for cell in nb["cells"]:
for cell in nb["cells"].copy():
cleaned |= _update_value(cell, "outputs", [])
cleaned |= _update_value(cell, "execution_count", None)
cleaned |= _update_value(cell, "metadata", _ignore(cell, ignore))
Expand Down
22 changes: 22 additions & 0 deletions tests/data/clean_empty_multi_cell.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9259e103-a9fe-4be1-8204-dfe194e8e978",
"metadata": {},
"outputs": [],
"source": [
"a = 2"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
72 changes: 72 additions & 0 deletions tests/data/dirty_empty_multi_cell.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "9259e103-a9fe-4be1-8204-dfe194e8e978",
"metadata": {},
"outputs": [],
"source": [
"a = 2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "5d06a671-1c6f-44b1-ad7b-ba26aaa020a2",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "3a4c8839",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "c08052ad",
"metadata": {},
"outputs": [],
"source": []
},
{
"cell_type": "code",
"execution_count": null,
"id": "50aad535",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "base",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.9"
},
"vscode": {
"interpreter": {
"hash": "5d4a37d74e2201ea12a12f96f8b5fbedd7b0b271dbcea21af2b23b61569be5db"
}
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion tests/test_clean_notebook.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def temp_path(tmp_path_factory: TempPathFactory) -> Iterator[Path]:
rmtree(dst)


TESTS = ["ascii", "jupyterlab", "vscode", "colab", "empty_cell"]
TESTS = ["ascii", "jupyterlab", "vscode", "colab", "empty_cell", "empty_multi_cell"]


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

0 comments on commit 16470d7

Please sign in to comment.