Ejemplo n.º 1
0
 def test_opts_image_cell_magic_offset(self):
     nbname = 'test_opts_image_cell_magic_offset.ipynb'
     # FIXME: Not quite right yet, shouldn't have a leading space or a newline
     expected = (" 'An expression (literal) on the same line';\n"
                 + """hv.util.opts(" Image [xaxis=None] (cmap='viridis')", """
                 + """hv.Image(np.random.rand(20,20)))""")
     source = apply_preprocessors([OptsMagicProcessor()], nbname)
     self.assertEqual(source.strip().endswith(expected), False)
Ejemplo n.º 2
0
 def test_opts_image_line_magic(self):
     nbname = 'test_opts_image_line_magic.ipynb'
     if sys.version_info.major == 2:
         expected = """hv.util.opts(u" Image [xaxis=None] (cmap='viridis')")"""
     else:
         expected = """hv.util.opts(" Image [xaxis=None] (cmap='viridis')")"""
     source = apply_preprocessors([OptsMagicProcessor()], nbname)
     self.assertEqual(source.strip().endswith(expected), True)
Ejemplo n.º 3
0
 def test_opts_image_cell_magic(self):
     nbname = 'test_opts_image_cell_magic.ipynb'
     if sys.version_info.major == 2:
         expected = (
             """hv.util.opts(u" Image [xaxis=None] (cmap='viridis')", """ +
             """hv.Image(np.random.rand(20,20)))""")
     else:
         expected = (
             """hv.util.opts(" Image [xaxis=None] (cmap='viridis')", """ +
             """hv.Image(np.random.rand(20,20)))""")
     source = apply_preprocessors([OptsMagicProcessor()], nbname)
     self.assertEqual(source.strip().endswith(expected), True)
Ejemplo n.º 4
0
def notebook_thumbnail(filename, subpath):
    basename = os.path.splitext(os.path.basename(filename))[0]
    dir_path = os.path.join(subpath, 'thumbnails')
    absdirpath= os.path.abspath(os.path.join('.', dir_path))
    if not os.path.exists(absdirpath):
        os.makedirs(absdirpath)

    preprocessors = [OptsMagicProcessor(),
                     OutputMagicProcessor(),
                     StripMagicsProcessor(),
                     ThumbnailProcessor(os.path.abspath(os.path.join(dir_path, basename)))]
    return export_to_python(filename, preprocessors)
Ejemplo n.º 5
0
def export_to_python(filename=None,
         preprocessors=[OptsMagicProcessor(),
                        OutputMagicProcessor(),
                        StripMagicsProcessor()]):

    filename = filename if filename else sys.argv[1]
    with open(filename) as f:
        nb = nbformat.read(f, nbformat.NO_CONVERT)
        exporter = nbconvert.PythonExporter()
        for preprocessor in preprocessors:
            exporter.register_preprocessor(preprocessor)
        source, meta = exporter.from_notebook_node(nb)
        return source