sphinx_nbexamples/__init__.py
def process_notebook(self, disable_warnings=True):
        """Process the notebook and create all the pictures and files

        This method runs the notebook using the :mod:`nbconvert` and
        :mod:`nbformat` modules. It creates the :attr:`outfile` notebook,
        a python and a rst file"""
        infile = self.infile
        outfile = self.outfile
        in_dir = os.path.dirname(infile) + os.path.sep
        odir = os.path.dirname(outfile) + os.path.sep
        create_dirs(os.path.join(odir, 'images'))
        ep = nbconvert.preprocessors.ExecutePreprocessor(
            timeout=300)
        cp = nbconvert.preprocessors.ClearOutputPreprocessor(
            timeout=300)

        self.nb = nb = nbformat.read(infile, nbformat.current_nbformat)
        # disable warnings in the rst file
        if disable_warnings:
            for i, cell in enumerate(nb.cells):
                if cell['cell_type'] == 'code':
                    cell = cell.copy()
                    break
            cell = cell.copy()
            cell.source = """
import logging
logging.captureWarnings(True)
logging.getLogger('py.warnings').setLevel(logging.ERROR)
"""
            nb.cells.insert(i, cell)
        # write and process rst_file
        if self.preprocess:
            t = dt.datetime.now()
            logger.info('Processing %s', self.infile)
            try:
                ep.preprocess(nb, {'metadata': {'path': in_dir}})
            except nbconvert.preprocessors.execute.CellExecutionError:
                logger.critical(
                    'Error while processing %s!', self.infile, exc_info=True)
            else:
                logger.info('Done. Seconds needed: %i',
                            (dt.datetime.now() - t).seconds)
            if disable_warnings:
                nb.cells.pop(i)

        self.py_file = self.get_out_file('py')

        if self.remove_tags:
            tp = nbconvert.preprocessors.TagRemovePreprocessor(timeout=300)
            for key, val in self.tag_options.items():
                setattr(tp, key, set(val))
            nb4rst = deepcopy(nb)
            tp.preprocess(nb4rst, {'metadata': {'path': in_dir}})
        else:
            nb4rst = nb

        self.create_rst(nb4rst, in_dir, odir)

        if self.clear:
            cp.preprocess(nb, {'metadata': {'path': in_dir}})
        # write notebook file
        nbformat.write(nb, outfile)
        self.create_py(nb)
def process_notebook(self, disable_warnings=True):
        infile = self.infile
        outfile = self.outfile
        in_dir = os.path.dirname(infile) + os.path.sep
        odir = os.path.dirname(outfile) + os.path.sep
        create_dirs(os.path.join(odir, 'images'))
        ep = nbconvert.preprocessors.ExecutePreprocessor(
            timeout=300)
        cp = nbconvert.preprocessors.ClearOutputPreprocessor(
            timeout=300)

        self.nb = nb = nbformat.read(infile, nbformat.current_nbformat)
        # disable warnings in the rst file
        if disable_warnings:
            for i, cell in enumerate(nb.cells):
                if cell['cell_type'] == 'code':
                    cell = cell.copy()
                    break
            cell = cell.copy()
            cell.source = """
import logging
logging.captureWarnings(True)
logging.getLogger('py.warnings').setLevel(logging.ERROR)
"""
            nb.cells.insert(i, cell)
        # write and process rst_file
        if self.preprocess:
            t = dt.datetime.now()
            logger.info('Processing %s', self.infile)
            try:
                ep.preprocess(nb, {'metadata': {'path': in_dir}})
            except nbconvert.preprocessors.execute.CellExecutionError:
                logger.critical(
                    'Error while processing %s!', self.infile, exc_info=True)
            else:
                logger.info('Done. Seconds needed: %i',
                            (dt.datetime.now() - t).seconds)
            if disable_warnings:
                nb.cells.pop(i)

        self.py_file = self.get_out_file('py')

        if self.remove_tags:
            tp = nbconvert.preprocessors.TagRemovePreprocessor(timeout=300)
            for key, val in self.tag_options.items():
                setattr(tp, key, set(val))
            nb4rst = deepcopy(nb)
            tp.preprocess(nb4rst, {'metadata': {'path': in_dir}})
        else:
            nb4rst = nb

        self.create_rst(nb4rst, in_dir, odir)

        if self.clear:
            cp.preprocess(nb, {'metadata': {'path': in_dir}})
        # write notebook file
        nbformat.write(nb, outfile)
        self.create_py(nb)
def process_notebook ( self , disable_warnings = True ) : infile = self . infile outfile = self . outfile in_dir = os . path . dirname ( infile ) + os . path . sep odir = os . path . dirname ( outfile ) + os . path . sep create_dirs ( os . path . join ( odir , 'images' ) ) ep = nbconvert . preprocessors . ExecutePreprocessor ( timeout = 300 ) cp = nbconvert . preprocessors . ClearOutputPreprocessor ( timeout = 300 ) self . nb = nb = nbformat . read ( infile , nbformat . current_nbformat ) # disable warnings in the rst file if disable_warnings : for i , cell in enumerate ( nb . cells ) : if cell [ 'cell_type' ] == 'code' : cell = cell . copy ( ) break cell = cell . copy ( ) cell . source = """
import logging
logging.captureWarnings(True)
logging.getLogger('py.warnings').setLevel(logging.ERROR)
""" nb . cells . insert ( i , cell ) # write and process rst_file if self . preprocess : t = dt . datetime . now ( ) logger . info ( 'Processing %s' , self . infile ) try : ep . preprocess ( nb , { 'metadata' : { 'path' : in_dir } } ) except nbconvert . preprocessors . execute . CellExecutionError : logger . critical ( 'Error while processing %s!' , self . infile , exc_info = True ) else : logger . info ( 'Done. Seconds needed: %i' , ( dt . datetime . now ( ) - t ) . seconds ) if disable_warnings : nb . cells . pop ( i ) self . py_file = self . get_out_file ( 'py' ) if self . remove_tags : tp = nbconvert . preprocessors . TagRemovePreprocessor ( timeout = 300 ) for key , val in self . tag_options . items ( ) : setattr ( tp , key , set ( val ) ) nb4rst = deepcopy ( nb ) tp . preprocess ( nb4rst , { 'metadata' : { 'path' : in_dir } } ) else : nb4rst = nb self . create_rst ( nb4rst , in_dir , odir ) if self . clear : cp . preprocess ( nb , { 'metadata' : { 'path' : in_dir } } ) # write notebook file nbformat . write ( nb , outfile ) self . create_py ( nb )
Process the notebook and create all the pictures and files

        This method runs the notebook using the :mod:`nbconvert` and
        :mod:`nbformat` modules. It creates the :attr:`outfile` notebook,
        a python and a rst file
Process the notebook and create all the pictures and files