Пример #1
0
 def validate_notebook_model(self, model):
     """Add failed-validation message to model"""
     try:
         current.validate(model['content'])
     except current.ValidationError as e:
         model['message'] = 'Notebook Validation failed: {}:\n{}'.format(
             e.message, json.dumps(e.instance, indent=1, default=lambda obj: '<UNKNOWN>'),
         )
     return model
Пример #2
0
def validate_notebook_at(path, version=None):
    if version is None:
        version = get_version(path)
    
    nb = open_nb(path, version)
    nb2 = upgrade(nb)
    try:
        current.validate(nb2, version=4)
    except ValidationError as e:
        return e
Пример #3
0
 def validate_notebook_model(self, model):
     """Add failed-validation message to model"""
     try:
         current.validate(model['content'])
     except current.ValidationError as e:
         model['message'] = 'Notebook Validation failed: {}:\n{}'.format(
             e.message,
             json.dumps(e.instance,
                        indent=1,
                        default=lambda obj: '<UNKNOWN>'),
         )
     return model
Пример #4
0
            resources = {}
            nb_name = os.path.splitext(os.path.basename(full_path))[0]
            nb_output_dirs = nb_name + args.outputs_dir_suffix
            resources['output_files_dir'] = nb_output_dirs

            # Clear old output dir path
            if os.path.isdir(os.path.join(build_dir, nb_output_dirs)):
                shutil.rmtree(os.path.join(build_dir, nb_output_dirs))

            exporter = RSTExporter()

            nb = nbformat.reads_json(open(full_path).read())

            if execute:
                log.info("Execute notebook '{}'".format(rel_path))
                nb = execute_notebook(nb, resources)

                if overwrite and len(nbformat.validate(nb)) == 0:
                    with open(full_path, 'w') as f:
                        nbformat.write(nb, f, 'ipynb')
                elif overwrite and len(nbformat.validate(nb)) > 0:
                    log.error("Executed notebook is not a valid format. "
                              "Original notebook won't be overwritten.")

            log.info("Export notebook '{}'".format(rel_path))
            (output, resources) = exporter.from_notebook_node(nb, resources=resources)

            writer = FilesWriter()
            writer.build_directory = build_dir
            writer.write(output, resources, notebook_name=nb_name)
Пример #5
0
            nb_name = os.path.splitext(os.path.basename(full_path))[0]
            nb_output_dirs = nb_name + args.outputs_dir_suffix[0]
            resources['output_files_dir'] = nb_output_dirs

            # Clear old output dir path
            if os.path.isdir(os.path.join(build_dir, nb_output_dirs)):
                shutil.rmtree(os.path.join(build_dir, nb_output_dirs))

            exporter = RSTExporter()

            nb = nbformat.reads_json(open(full_path).read())

            if execute:
                log.info("Execute notebook '{}'".format(rel_path))
                nb = execute_notebook(nb, resources)

                if overwrite and len(nbformat.validate(nb)) == 0:
                    with open(full_path, 'w') as f:
                        nbformat.write(nb, f, 'ipynb')
                elif overwrite and len(nbformat.validate(nb)) > 0:
                    log.error("Executed notebook is not a valid format. "
                              "Original notebook won't be overwritten.")

            log.info("Export notebook '{}'".format(rel_path))
            (output,
             resources) = exporter.from_notebook_node(nb, resources=resources)

            writer = FilesWriter()
            writer.build_directory = build_dir
            writer.write(output, resources, notebook_name=nb_name)