Skip to content

Commit

Permalink
improvements to the docstrings and correct usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mpacer committed Aug 7, 2017
1 parent c0b2a79 commit 175b9c7
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 15 deletions.
2 changes: 1 addition & 1 deletion nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def default_config(self):
'TagRemovePreprocessor': {
'enabled': True
},
'TagInputRemoveSieve': {
'TagRemoveInputSieve': {
'enabled': True
}
})
Expand Down
22 changes: 10 additions & 12 deletions nbconvert/sieves/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@
class Sieve(NbConvertBase):
""" A configurable sieve
Inherit from this class if you wish to have configurability for your
sieve.
Inherit from this class if you wish to have a configurable sieve.
Any configurable traitlets this class exposed will be configurable in
Any configurable traitlets this class exposes will be configurable in
profiles using c.SubClassName.attribute = value
you can overwrite :meth:`sieve_cell` to apply a transformation
You can overwrite :meth:`sieve_cell` to apply a transformation
independently on each cell or :meth:`sieve` if you prefer your own
logic. See corresponding docstring for informations.
logic. See corresponding docstring for further information.
Disabled by default and can be enabled via the config by
'c.YourSieveName.enabled = True'
Expand Down Expand Up @@ -50,12 +49,12 @@ def __call__(self, nb, resources):

def sieve(self, nb, resources):
"""
Preprocessing to apply on each notebook.
Sieve to apply on each notebook.
Must return modified nb, resources.
If you wish to apply your preprocessing to each cell, you might want
to override preprocess_cell method instead.
If you wish to apply your sieve to each cell, you might want
to override sieve_cell method instead.
Parameters
----------
Expand All @@ -65,15 +64,15 @@ def sieve(self, nb, resources):
Additional resources used in the conversion process. Allows
sieves to pass variables into the Jinja engine.
"""
for index, cell in enumerate(nb.cells):
nb.cells[index], resources = self.sieve_cell(cell, resources, index)
for ind, cell in enumerate(nb.cells):
nb.cells[ind], resources = self.sieve_cell(cell, resources, ind)
return nb, resources

def sieve_cell(self, cell, resources, index):
"""
Override if you want to sieve each cell.
Must return modified cell and resource dictionary.
Parameters
----------
cell : NotebookNode cell
Expand All @@ -87,4 +86,3 @@ def sieve_cell(self, cell, resources, index):

raise NotImplementedError('should be implemented by subclass')
return cell, resources

7 changes: 5 additions & 2 deletions nbconvert/sieves/taginput.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ class TagRemoveInputSieve(Sieve):

def sieve(self, nb, resources):
"""
Preprocessing to apply to each notebook. See base.py for details.
Sieve to apply to each notebook. See base.py for details.
"""
# Skip preprocessing if the list of patterns is empty
# Skip sieve if the list of patterns is empty
if not self.remove_input_tags:
return nb, resources

Expand All @@ -25,6 +25,9 @@ def sieve(self, nb, resources):


def sieve_cell(self, cell, resources, cell_index):
"""
Apply sieve to individual cell.
"""

if (self.remove_input_tags.intersection(
cell.get('metadata', {}).get('tags', []))):
Expand Down

0 comments on commit 175b9c7

Please sign in to comment.