##// END OF EJS Templates
Merge pull request #7387 from minrk/system-wide-nbextensions...
Merge pull request #7387 from minrk/system-wide-nbextensions allow system-wide installtion of nbextensions

File last commit:

r18580:ba8461eb
r19862:6a4192ef merge
Show More
base.py
92 lines | 2.8 KiB | text/x-python | PythonLexer
MinRK
improve logging in nbconvert preprocessors...
r16207 """Base class for preprocessors"""
Jonathan Frederic
Cleanup and refactor, transformers
r10674
MinRK
improve logging in nbconvert preprocessors...
r16207 # Copyright (c) IPython Development Team.
# Distributed under the terms of the Modified BSD License.
Matthias BUSSONNIER
move transformer in separate file
r9302
Jonathan Frederic
Rename utils.config to utils.base
r11420 from ..utils.base import NbConvertBase
Jonathan Frederic
Removed ActivatableTransformer and moved enabled key into base.
r11388 from IPython.utils.traitlets import Bool
Matthias BUSSONNIER
create configurable preprocessors
r9307
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 class Preprocessor(NbConvertBase):
""" A configurable preprocessor
Matthias BUSSONNIER
docs
r9528
Inherit from this class if you wish to have configurability for your
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 preprocessor.
Matthias BUSSONNIER
docs
r9528
Paul Ivanov
fixup minor typos from search/replace
r12220 Any configurable traitlets this class exposed will be configurable in
MinRK
improve logging in nbconvert preprocessors...
r16207 profiles using c.SubClassName.attribute = value
Matthias BUSSONNIER
docs
r9528
Paul Ivanov
fixup minor typos from search/replace
r12220 you can overwrite :meth:`preprocess_cell` to apply a transformation
independently on each cell or :meth:`preprocess` if you prefer your own
logic. See corresponding docstring for informations.
Jonathan Frederic
Removed ActivatableTransformer and moved enabled key into base.
r11388
Disabled by default and can be enabled via the config by
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 'c.YourPreprocessorName.enabled = True'
Matthias BUSSONNIER
docs
r9528 """
Jonathan Frederic
Generator used to create figure indicies
r10772
Jonathan Frederic
Prefer new style of config passing, parent=self (replaces config=self.config)
r11382 enabled = Bool(False, config=True)
def __init__(self, **kw):
Jonathan Frederic
Cleanup and refactor, transformers
r10674 """
Public constructor
Parameters
----------
config : Config
Configuration file structure
**kw : misc
Additional arguments
"""
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 super(Preprocessor, self).__init__(**kw)
Matthias BUSSONNIER
create configurable preprocessors
r9307
Jonathan Frederic
Generator used to create figure indicies
r10772
Jonathan Frederic
Cleanup and refactor, transformers
r10674 def __call__(self, nb, resources):
Jonathan Frederic
Removed ActivatableTransformer and moved enabled key into base.
r11388 if self.enabled:
MinRK
improve logging in nbconvert preprocessors...
r16207 self.log.debug("Applying preprocessor: %s", self.__class__.__name__)
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 return self.preprocess(nb,resources)
Jonathan Frederic
Removed ActivatableTransformer and moved enabled key into base.
r11388 else:
return nb, resources
Matthias BUSSONNIER
do not ask to inherit __call__ but call
r10834
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def preprocess(self, nb, resources):
Jonathan Frederic
Cleanup and refactor, transformers
r10674 """
Paul Ivanov
fixup minor typos from search/replace
r12220 Preprocessing to apply on each notebook.
Jonathan Frederic
Cleanup and refactor, transformers
r10674
MinRK
improve logging in nbconvert preprocessors...
r16207 Must return modified nb, resources.
Paul Ivanov
fixup minor typos from search/replace
r12220 If you wish to apply your preprocessing to each cell, you might want
MinRK
improve logging in nbconvert preprocessors...
r16207 to override preprocess_cell method instead.
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Parameters
----------
nb : NotebookNode
Notebook being converted
resources : dictionary
Additional resources used in the conversion process. Allows
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 preprocessors to pass variables into the Jinja engine.
Matthias BUSSONNIER
docs
r9528 """
MinRK
update nbconvert to nbformat 4
r18580 for index, cell in enumerate(nb.cells):
nb.cells[index], resources = self.preprocess_cell(cell, resources, index)
MinRK
improve logging in nbconvert preprocessors...
r16207 return nb, resources
Matthias BUSSONNIER
create configurable preprocessors
r9307
Matthias BUSSONNIER
docs
r9528
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 def preprocess_cell(self, cell, resources, index):
Jonathan Frederic
Cleanup and refactor, transformers
r10674 """
MinRK
improve logging in nbconvert preprocessors...
r16207 Override if you want to apply some preprocessing to each cell.
Must return modified cell and resource dictionary.
Jonathan Frederic
Cleanup and refactor, transformers
r10674
Parameters
----------
cell : NotebookNode cell
Notebook cell being processed
resources : dictionary
Additional resources used in the conversion process. Allows
Paul Ivanov
replace 'transformer' with 'preprocessor'
r12219 preprocessors to pass variables into the Jinja engine.
Jonathan Frederic
Cleanup and refactor, transformers
r10674 index : int
Index of the cell being processed
Matthias BUSSONNIER
create configurable preprocessors
r9307 """
Jonathan Frederic
Post code-review, extended refactor.
r10485
Matthias BUSSONNIER
create configurable preprocessors
r9307 raise NotImplementedError('should be implemented by subclass')
Jonathan Frederic
Cleanup and refactor, transformers
r10674 return cell, resources
Matthias BUSSONNIER
do not ask to inherit __call__ but call
r10834