Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

avoid svg+xml images when cleaning #8

Merged
merged 5 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@

# 0.2.3 (2022-02-15)

### Fixed

- Do not attempt to clean `"image/svg+xml"` images

# 0.2.2 (2022-02-11)

### Added
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
requirements = [c.strip() for c in f.readlines()]

setup(name="nbcleanmeta",
version="0.2.2",
version="0.2.3",
description="Le Wagon notebook metadata cleaner tool",
url="https://github.com/lewagon/nbcleanmeta/",
author="Sébastien Saunier",
Expand Down
10 changes: 4 additions & 6 deletions tests/test_cleaner_outputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,8 @@ def test_outputs_data_trailing_newline_is_present(self, notebook_path):
code_cells = self._get_code_cells(clean_content)
for cell in code_cells:
for output in cell.get('outputs', []):
for data_key in output.get('data', {}):
if data_key[:6] == 'image/':
assert output['data'][data_key][-1:] == '\n'
if 'image/png' in output.get('data', {}):
assert output['data']['image/png'][-1:] == '\n'

def test_outputs_data_trailing_newline_is_removed(self, notebook_path):
# Act
Expand All @@ -31,6 +30,5 @@ def test_outputs_data_trailing_newline_is_removed(self, notebook_path):
code_cells = self._get_code_cells(clean_content)
for cell in code_cells:
for output in cell.get('outputs', []):
for data_key in output.get('data', {}):
if data_key[:6] == 'image/':
assert output['data'][data_key][-1:] != '\n'
if 'image/png' in output.get('data', {}):
assert output['data']['image/png'][-1:] != '\n'
7 changes: 3 additions & 4 deletions wagon_cleaner/run_clean.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,9 @@ def edit_notebook(notebook_content, notebook_path, kwargs, delete_notes=False):
if "execution_count" in output:
output["execution_count"] = None

# clean outputs data image trailing newline
for data_key in output.get("data", {}):
if data_key[:6] == "image/":
output["data"][data_key] = output["data"][data_key].rstrip("\n")
# clean outputs data image trailing newline (avoid "image/svg+xml")
if "image/png" in output.get("data", {}):
output["data"]["image/png"] = output["data"]["image/png"].rstrip("\n")

# clean cell metadata
if "metadata" in cell:
Expand Down