##// END OF EJS Templates
log, don’t raise on validation failure in v4.convert
MinRK -
Show More
@@ -11,6 +11,7 b' from .nbbase import ('
11 )
11 )
12
12
13 from IPython.nbformat import v3
13 from IPython.nbformat import v3
14 from IPython.utils.log import get_logger
14
15
15
16
16 def upgrade(nb, from_version=3, from_minor=0):
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 from_minor : int
26 from_minor : int
26 The original minor version of the notebook to convert (only relevant for v >= 3).
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 if from_version == 3:
30 if from_version == 3:
30 # Validate the notebook before conversion
31 # Validate the notebook before conversion
32 try:
31 validate(nb, version=from_version)
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 # Mark the original nbformat so consumers know it has been converted.
37 # Mark the original nbformat so consumers know it has been converted.
38 nb.pop('orig_nbformat', None)
34 nb.metadata.orig_nbformat = 3
39 nb.metadata.orig_nbformat = 3
35 # Mark the new format
40 # Mark the new format
36 nb.nbformat = nbformat
41 nb.nbformat = nbformat
@@ -47,7 +52,10 b' def upgrade(nb, from_version=3, from_minor=0):'
47 # upgrade metadata
52 # upgrade metadata
48 nb.metadata.pop('name', '')
53 nb.metadata.pop('name', '')
49 # Validate the converted notebook before returning it
54 # Validate the converted notebook before returning it
55 try:
50 validate(nb, version=nbformat)
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 return nb
59 return nb
52 elif from_version == 4:
60 elif from_version == 4:
53 # nothing to do
61 # nothing to do
General Comments 0
You need to be logged in to leave comments. Login now