def _notebook_run(path):
 kernel_name = ('python%d' % sys.version_info[0])
 this_file_directory = os.path.dirname(__file__)
 errors = []
 with tempfile.NamedTemporaryFile(suffix='.ipynb', mode='wt') as fout:
  with open(path) as f:
   nb = nbformat.read(f, as_version=4)
   nb.metadata.get('kernelspec', {})['name'] = kernel_name
   ep = ExecutePreprocessor(kernel_name=kernel_name, timeout=10)
   try:
    ep.preprocess(nb, {'metadata': {'path': this_file_directory}})
   except CellExecutionError as e:
    if ('SKIP' in e.traceback):
     print str(e.traceback).split('\n')[(-2)]
    else:
     raise e
   except TimeoutError as e:
    print e
   finally:
    nbformat.write(nb, fout)
 return (nb, errors)

def _notebook_run ( path ) : kernel_name = ( 'python%d' % sys . version_info [ 0 ] ) this_file_directory = os . path . dirname ( __file__ ) errors = [ ] with tempfile . NamedTemporaryFile ( suffix = '.ipynb' , mode = 'wt' ) as fout : with open ( path ) as f : nb = nbformat . read ( f , as_version = 4 ) nb . metadata . get ( 'kernelspec' , { } ) [ 'name' ] = kernel_name ep = ExecutePreprocessor ( kernel_name = kernel_name , timeout = 10 ) try : ep . preprocess ( nb , { 'metadata' : { 'path' : this_file_directory } } ) except CellExecutionError as e : if ( 'SKIP' in e . traceback ) : print str ( e . traceback ) . split ( '\n' ) [ ( - 2 ) ] else : raise e except TimeoutError as e : print e finally : nbformat . write ( nb , fout ) return ( nb , errors )
execute a notebook via nbconvert and collect output .