Ejemplo n.º 1
0
 def test_opts_image_line_magic(self):
     nbname = 'test_output_svg_line_magic.ipynb'
     if sys.version_info.major == 2:
         expected = """hv.util.output(u" fig='svg'")"""
     else:
         expected = """hv.util.output(" fig='svg'")"""
     source = apply_preprocessors([OutputMagicProcessor()], nbname)
     self.assertEqual(source.strip().endswith(expected), True)
Ejemplo n.º 2
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.º 3
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
Ejemplo n.º 4
0
 def test_opts_image_line_magic_svg(self):
     nbname = 'test_output_svg_line_magic.ipynb'
     expected = """hv.util.output(" fig='svg'")"""
     source = apply_preprocessors([OutputMagicProcessor()], nbname)
     self.assertEqual(source.strip().endswith(expected), True)