Skip to content

Commit

Permalink
Merge pull request #1312 from MSeal/clear-output-fix
Browse files Browse the repository at this point in the history
Removed inheritance breaking clear-output option
  • Loading branch information
SylvainCorlay authored Jul 2, 2020
2 parents b1294dd + 4f616ef commit c929426
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
1 change: 1 addition & 0 deletions nbconvert/preprocessors/clearoutput.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from traitlets import Set
from .base import Preprocessor


class ClearOutputPreprocessor(Preprocessor):
"""
Removes the output from all code cells in a notebook.
Expand Down
8 changes: 5 additions & 3 deletions nbconvert/preprocessors/tagremove.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@
# Distributed under the terms of the Modified BSD License.

from traitlets import Set, Unicode
from . import ClearOutputPreprocessor
from .base import Preprocessor


class TagRemovePreprocessor(ClearOutputPreprocessor):
class TagRemovePreprocessor(Preprocessor):
"""
Removes inputs, outputs, or cells from a notebook that
have tags that designate they are to be removed prior to exporting
Expand Down Expand Up @@ -44,7 +44,9 @@ class TagRemovePreprocessor(ClearOutputPreprocessor):
remove_input_tags = Set(Unicode(), default_value=[],
help=("Tags indicating cells for which input is to be removed,"
"matches tags in `cell.metadata.tags`.")).tag(config=True)

remove_metadata_fields = Set(
{'collapsed', 'scrolled'}
).tag(config=True)

def check_cell_conditions(self, cell, resources, index):
"""
Expand Down
15 changes: 15 additions & 0 deletions nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

import os
import io
import nbformat

from .base import TestsBase
from ..postprocessors import PostProcessorBase
Expand Down Expand Up @@ -90,6 +91,20 @@ def test_explicit(self):
assert not os.path.isfile('notebook1.py')
assert os.path.isfile('notebook2.py')

def test_clear_output(self):
"""
Can we clear outputs?
"""
with self.create_temp_cwd(['notebook*.ipynb']) as td:
self.nbconvert('--clear-output notebook1')
assert os.path.isfile('notebook1.ipynb')
with open('notebook1.ipynb', encoding='utf8') as f:
nb = nbformat.read(f, 4)
for cell in nb.cells:
# Skip markdown cells
if 'outputs' in cell:
assert cell.outputs == []

def test_absolute_template_file(self):
"""--template-file '/path/to/template.tpl'"""
with self.create_temp_cwd(['notebook*.ipynb']), tempdir.TemporaryDirectory() as td:
Expand Down

0 comments on commit c929426

Please sign in to comment.