From bd730f7041f449d66a88199028e3b97dc608f568 2014-11-01 23:41:01 From: MinRK Date: 2014-11-01 23:41:01 Subject: [PATCH] update nbformat.current to v4 --- diff --git a/IPython/nbformat/convert.py b/IPython/nbformat/convert.py index 049883a..fea1148 100644 --- a/IPython/nbformat/convert.py +++ b/IPython/nbformat/convert.py @@ -1,26 +1,10 @@ -"""API for converting notebooks between versions. +"""API for converting notebooks between versions.""" -Authors: - -* Jonathan Frederic -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from .reader import get_version, versions -#----------------------------------------------------------------------------- -# Functions -#----------------------------------------------------------------------------- def convert(nb, to_version): """Convert a notebook node object to a specific version. Assumes that @@ -60,11 +44,11 @@ def convert(nb, to_version): # Convert and make sure version changed during conversion. converted = convert_function(nb) if converted.get('nbformat', 1) == version: - raise Exception("Cannot convert notebook from v%d to v%d. Operation" \ + raise ValueError("Cannot convert notebook from v%d to v%d. Operation" \ "failed silently." % (version, step_version)) # Recursively convert until target version is reached. return convert(converted, to_version) else: - raise Exception("Cannot convert notebook to v%d because that " \ + raise ValueError("Cannot convert notebook to v%d because that " \ "version doesn't exist" % (to_version)) diff --git a/IPython/nbformat/reader.py b/IPython/nbformat/reader.py index bb94ee4..158e071 100644 --- a/IPython/nbformat/reader.py +++ b/IPython/nbformat/reader.py @@ -1,36 +1,22 @@ -"""API for reading notebooks. +"""API for reading notebooks of different versions""" -Authors: - -* Jonathan Frederic -""" - -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. import json from . import v1 from . import v2 from . import v3 +from . import v4 versions = { 1: v1, 2: v2, 3: v3, + 4: v4, } -#----------------------------------------------------------------------------- -# Code -#----------------------------------------------------------------------------- class NotJSONError(ValueError): pass diff --git a/IPython/nbformat/sign.py b/IPython/nbformat/sign.py index 7040492..a8d7390 100644 --- a/IPython/nbformat/sign.py +++ b/IPython/nbformat/sign.py @@ -17,7 +17,6 @@ from IPython.core.application import BaseIPythonApplication, base_flags from .current import read, write - try: # Python 3 algorithms = hashlib.algorithms_guaranteed @@ -181,10 +180,10 @@ class NotebookNotary(LoggingConfigurable): This function is the inverse of check_cells """ - if not nb['worksheets']: + if not nb['cells']: # nothing to mark if there are no cells return - for cell in nb['worksheets'][0]['cells']: + for cell in nb['cells']: if cell['cell_type'] == 'code': cell['metadata']['trusted'] = trusted @@ -206,12 +205,11 @@ class NotebookNotary(LoggingConfigurable): # explicitly safe output safe = { 'text/plain', 'image/png', 'image/jpeg', - 'text', 'png', 'jpg', # v3-style short keys } for output in cell['outputs']: output_type = output['output_type'] - if output_type in ('pyout', 'display_data'): + if output_type in {'execute_result', 'display_data'}: # if there are any data keys not in the safe whitelist output_keys = set(output).difference({"output_type", "prompt_number", "metadata"}) if output_keys.difference(safe): @@ -226,10 +224,10 @@ class NotebookNotary(LoggingConfigurable): This function is the inverse of mark_cells. """ - if not nb['worksheets']: + if not nb['cells']: return True trusted = True - for cell in nb['worksheets'][0]['cells']: + for cell in nb['cells']: if cell['cell_type'] != 'code': continue # only distrust a cell if it actually has some output to distrust diff --git a/IPython/nbformat/tests/test4.ipynb b/IPython/nbformat/tests/test4.ipynb new file mode 100644 index 0000000..1862a76 --- /dev/null +++ b/IPython/nbformat/tests/test4.ipynb @@ -0,0 +1,155 @@ +{ + "metadata": { + "cell_tags": ["", null], + "name": "", + "kernel_info": { + "name": "python", + "language": "python" + } + }, + "nbformat": 4, + "nbformat_minor": 0, + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "nbconvert latex test" + ] + }, + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "**Lorem ipsum** dolor sit amet, consectetur adipiscing elit. Nunc luctus bibendum felis dictum sodales. Ut suscipit, orci ut interdum imperdiet, purus ligula mollis *justo*, non malesuada nisl augue eget lorem. Donec bibendum, erat sit amet porttitor aliquam, urna lorem ornare libero, in vehicula diam diam ut ante. Nam non urna rhoncus, accumsan elit sit amet, mollis tellus. Vestibulum nec tellus metus. Vestibulum tempor, ligula et vehicula rhoncus, sapien turpis faucibus lorem, id dapibus turpis mauris ac orci. Sed volutpat vestibulum venenatis." + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Printed Using Python" + ] + }, + { + "cell_type": "code", + "source": [ + "print(\"hello\")" + ], + "metadata": { + "collapsed": false, + "autoscroll": false + }, + "outputs": [ + { + "output_type": "stream", + "metadata": {}, + "name": "stdout", + "text": [ + "hello\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Pyout" + ] + }, + { + "cell_type": "code", + "source": [ + "from IPython.display import HTML\n", + "HTML(\"\"\"\n", + "\n", + "HTML\n", + "\"\"\")" + ], + "metadata": { + "collapsed": false, + "autoscroll": false + }, + "outputs": [ + { + "text/html": [ + "\n", + "\n", + "HTML\n" + ], + "metadata": {}, + "output_type": "execute_result", + "prompt_number": 3, + "text/plain": [ + "" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "code", + "source": [ + "%%javascript\n", + "console.log(\"hi\");" + ], + "metadata": { + "collapsed": false, + "autoscroll": false + }, + "outputs": [ + { + "text/javascript": [ + "console.log(\"hi\");" + ], + "metadata": {}, + "output_type": "display_data", + "text/plain": [ + "" + ] + } + ], + "prompt_number": 7 + }, + { + "cell_type": "heading", + "level": 3, + "metadata": {}, + "source": [ + "Image" + ] + }, + { + "cell_type": "code", + "source": [ + "from IPython.display import Image\n", + "Image(\"http://ipython.org/_static/IPy_header.png\")" + ], + "metadata": { + "collapsed": false, + "autoscroll": false + }, + "outputs": [ + { + "metadata": {}, + "output_type": "execute_result", + "image/png": "iVBORw0KGgoAAAANSUhEUgAAAggAAABDCAYAAAD5/P3lAAAABHNCSVQICAgIfAhkiAAAAAlwSFlz\nAAAH3AAAB9wBYvxo6AAAABl0RVh0U29mdHdhcmUAd3d3Lmlua3NjYXBlLm9yZ5vuPBoAACAASURB\nVHic7Z15uBxF1bjfugkJhCWBsCSAJGACNg4QCI3RT1lEAVE+UEBNOmwCDcjHT1wQgU+WD3dFxA1o\nCAikAZFFVlnCjizpsCUjHQjBIAkQlpCFJGS79fvjdGf69vTsc2fuza33eeaZmeqq6jM9vZw6dc4p\nBUwC+tE+fqW1fqmRDpRSHjCggS40sBxYDCxKvL8KzNBaL21EPoPB0DPIWVY/4NlE0ffzYfhgu+Qx\nGHoy/YFjaK+CcB3QkIIAHAWs3wRZsuhUSs0CXgQeBm7UWi/spn0Z+jA5yxpEfYruqnwYllRic5a1\nMaWv8U5gaT4M19Sx396IAnZLfB/SLkEMhp5O/3YL0AvoAHaKXl8HLlZK3QZcpbWe0lbJDOsaHuDU\n0e4u4JAy2wPk/C1JzrKWArOQ0fUtwH35MOysQxaDwbCO0NFuAXoh6wPjgQeUUvcqpUa0WyCDoQls\nCIwBjgfuAV7KWdY+7RWpmJxlXZezrEdylvXxdstiMKzrGAtCYxwI/EspdZbW+g/tFsbQ67kQuBHY\nFNgseh9FV6vCbUAeWBC9PgBeq2EfS6J2MQOBrRDTe5KdgAdzlvW1fBjeUUP/3UbOsoYBE6OvG7VT\nFoOhL9Af+BUwFLkZpV+DaY6V4UPkRpb1+ncT+m8nGwK/V0oN01qf025hDL2XfBi+DLycLMtZVo6u\nCsKfGnSq8/NheEpqHwOBEcDBwJnAsGhTP2ByzrJG5cPwnQb22Sy+0G4BDIa+RH+t9dmlNiqlFKIk\nJJWGi+jq5JPmq8BbJJQArfXqpkncczlbKbVQa/3rdgtiM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nIlaWk5Br93wkk+jztusP7o94Lna7eaoMZU0cVXIAped7eqGZfP2ZqmPFl+ptrVf3n19UpvVMYLRS\nagBywxuEjLwWAe9qrTMXV2mUzs7OP/Xrp+6qt33Hmn5Zue3XNeZTOVoky5nqKiQkrNT883Qk3WvJ\nsMLAc1bbrv9Z5AH6KWRkOB+5wRWlWo7a3Ga7/mOIomAho/GFyI30YeDREru7ELlOq07TG3jONbbr\nT0Nu9KOQm+i/gFsDz3nTdv2fI2FbpdpfHnlpH4LcnHdAlIz5yLErqXgFnvOR7fo28lDYE7lu3kKO\nTdZ9K52xrhTl7knnUVB6SqVeTsr4apQU6lDEbG4hCsFbROsRBE1ebjrwnNB2/XGIGf5gRBkYhPyv\n7yDpjR9MtVkOnGK7/vWIgrFrVPcF4O8ZKbaXIuduWkH6KfL/JbkEsWClfWK2CDzHt10/jzhXjkGO\nyzNIZEiRD00ga3ocaLv+kUh2xo8hSuVURKmIUyiXVGYCWVzKQlJD7xrJNg85b9LX8RLgF6X6SpFU\n9Cpe28gaJgORqEEAbNffDLlvHIQoAndR8NEYilwjExD/nwuUiTQ0GAwGw7qC7fqjEUvKqsBzmhWd\nt05gu/5pyNoifw48J9N5PForxQeeNFMMBoPBYDD0DWL/llvK1In9jt4zCoLBYDAYDH2DePo5MwrJ\ndv0hFPwTnjBRDAaDwWAw9A3+hPgOHRPl25iK+FhsiuR4OARx0Lwf+J1REAwGg8Fg6AMEnvNklL78\nHMRRca/E5hVINNIVwI2B56z6/3ExLRI31pXNAAAAAElFTkSuQmCC\n", + "prompt_number": 6, + "text/plain": [ + "" + ] + } + ], + "prompt_number": 6 + } + ] +} diff --git a/IPython/nbformat/tests/test_convert.py b/IPython/nbformat/tests/test_convert.py index 9eb45ad..19c8b35 100644 --- a/IPython/nbformat/tests/test_convert.py +++ b/IPython/nbformat/tests/test_convert.py @@ -1,16 +1,7 @@ -""" -Contains tests class for convert.py -""" -#----------------------------------------------------------------------------- -# Copyright (C) 2013 The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- - -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +"""Tests for nbformat.convert""" + +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from .base import TestsBase @@ -18,13 +9,10 @@ from ..convert import convert from ..reader import read, get_version from ..current import current_nbformat -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- class TestConvert(TestsBase): - def test_downgrade(self): + def test_downgrade_3_2(self): """Do notebook downgrades work?""" # Open a version 3 notebook and attempt to downgrade it to version 2. @@ -37,7 +25,7 @@ class TestConvert(TestsBase): self.assertEqual(major, 2) - def test_upgrade(self): + def test_upgrade_2_3(self): """Do notebook upgrades work?""" # Open a version 2 notebook and attempt to upgrade it to version 3. diff --git a/IPython/nbformat/tests/test_sign.py b/IPython/nbformat/tests/test_sign.py index e0b91c1..5534105 100644 --- a/IPython/nbformat/tests/test_sign.py +++ b/IPython/nbformat/tests/test_sign.py @@ -1,14 +1,7 @@ """Test Notebook signing""" -#----------------------------------------------------------------------------- -# Copyright (C) 2014, The IPython Development Team -# -# Distributed under the terms of the BSD License. The full license is in -# the file COPYING, distributed as part of this software. -#----------------------------------------------------------------------------- -#----------------------------------------------------------------------------- -# Imports -#----------------------------------------------------------------------------- +# Copyright (c) IPython Development Team. +# Distributed under the terms of the Modified BSD License. from .. import sign from .base import TestsBase @@ -16,9 +9,6 @@ from .base import TestsBase from ..current import read from IPython.core.getipython import get_ipython -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- class TestNotary(TestsBase): @@ -80,7 +70,7 @@ class TestNotary(TestsBase): self.assertTrue(check_signature(nb)) def test_mark_cells_untrusted(self): - cells = self.nb.worksheets[0].cells + cells = self.nb.cells self.notary.mark_cells(self.nb, False) for cell in cells: self.assertNotIn('trusted', cell) @@ -91,7 +81,7 @@ class TestNotary(TestsBase): self.assertNotIn('trusted', cell.metadata) def test_mark_cells_trusted(self): - cells = self.nb.worksheets[0].cells + cells = self.nb.cells self.notary.mark_cells(self.nb, True) for cell in cells: self.assertNotIn('trusted', cell) @@ -105,17 +95,17 @@ class TestNotary(TestsBase): nb = self.nb self.notary.mark_cells(nb, True) self.assertTrue(self.notary.check_cells(nb)) - for cell in nb.worksheets[0].cells: + for cell in nb.cells: self.assertNotIn('trusted', cell) self.notary.mark_cells(nb, False) self.assertFalse(self.notary.check_cells(nb)) - for cell in nb.worksheets[0].cells: + for cell in nb.cells: self.assertNotIn('trusted', cell) def test_trust_no_output(self): nb = self.nb self.notary.mark_cells(nb, False) - for cell in nb.worksheets[0].cells: + for cell in nb.cells: if cell.cell_type == 'code': cell.outputs = [] self.assertTrue(self.notary.check_cells(nb)) diff --git a/IPython/nbformat/tests/test_validator.py b/IPython/nbformat/tests/test_validator.py index 1da734f..eb91953 100644 --- a/IPython/nbformat/tests/test_validator.py +++ b/IPython/nbformat/tests/test_validator.py @@ -11,14 +11,10 @@ from ..current import read from ..validator import isvalid, validate -#----------------------------------------------------------------------------- -# Classes and functions -#----------------------------------------------------------------------------- - class TestValidator(TestsBase): def test_nb2(self): - """Test that a v2 notebook converted to v3 passes validation""" + """Test that a v2 notebook converted to current passes validation""" with self.fopen(u'test2.ipynb', u'r') as f: nb = read(f, u'json') validate(nb) @@ -31,6 +27,13 @@ class TestValidator(TestsBase): validate(nb) self.assertEqual(isvalid(nb), True) + def test_nb4(self): + """Test that a v3 notebook passes validation""" + with self.fopen(u'test4.ipynb', u'r') as f: + nb = read(f, u'json') + validate(nb) + self.assertEqual(isvalid(nb), True) + def test_invalid(self): """Test than an invalid notebook does not pass validation""" # this notebook has a few different errors: diff --git a/IPython/nbformat/v4/__init__.py b/IPython/nbformat/v4/__init__.py index 9c02b03..0538056 100644 --- a/IPython/nbformat/v4/__init__.py +++ b/IPython/nbformat/v4/__init__.py @@ -4,7 +4,7 @@ # Distributed under the terms of the Modified BSD License. from .nbbase import ( - NotebookNode, + NotebookNode, from_dict, nbformat, nbformat_minor, nbformat_schema, new_code_cell, new_heading_cell, new_markdown_cell, new_notebook, new_output,