Show More
@@ -11,6 +11,7 b' from .nbbase import (' | |||
|
11 | 11 | ) |
|
12 | 12 | |
|
13 | 13 | from IPython.nbformat import v3 |
|
14 | from IPython.utils.log import get_logger | |
|
14 | 15 | |
|
15 | 16 | |
|
16 | 17 | def upgrade(nb, from_version=3, from_minor=0): |
@@ -25,12 +26,16 b' def upgrade(nb, from_version=3, from_minor=0):' | |||
|
25 | 26 | from_minor : int |
|
26 | 27 | The original minor version of the notebook to convert (only relevant for v >= 3). |
|
27 | 28 | """ |
|
28 | from IPython.nbformat.current import validate | |
|
29 | from IPython.nbformat.current import validate, ValidationError | |
|
29 | 30 | if from_version == 3: |
|
30 | 31 | # Validate the notebook before conversion |
|
32 | try: | |
|
31 | 33 | validate(nb, version=from_version) |
|
34 | except ValidationError as e: | |
|
35 | get_logger().error("Notebook JSON is not valid v%i: %s", from_version, e) | |
|
32 | 36 | |
|
33 | 37 | # Mark the original nbformat so consumers know it has been converted. |
|
38 | nb.pop('orig_nbformat', None) | |
|
34 | 39 | nb.metadata.orig_nbformat = 3 |
|
35 | 40 | # Mark the new format |
|
36 | 41 | nb.nbformat = nbformat |
@@ -47,7 +52,10 b' def upgrade(nb, from_version=3, from_minor=0):' | |||
|
47 | 52 | # upgrade metadata |
|
48 | 53 | nb.metadata.pop('name', '') |
|
49 | 54 | # Validate the converted notebook before returning it |
|
55 | try: | |
|
50 | 56 | validate(nb, version=nbformat) |
|
57 | except ValidationError as e: | |
|
58 | get_logger().error("Notebook JSON is not valid v%i: %s", nbformat, e) | |
|
51 | 59 | return nb |
|
52 | 60 | elif from_version == 4: |
|
53 | 61 | # nothing to do |
General Comments 0
You need to be logged in to leave comments.
Login now