Show More
@@ -1,4 +1,4 b'' | |||||
1 |
"""The main API for the v |
|
1 | """The main API for the v3 notebook format. | |
2 |
|
2 | |||
3 | Authors: |
|
3 | Authors: | |
4 |
|
4 | |||
@@ -19,7 +19,7 b' Authors:' | |||||
19 | from .nbbase import ( |
|
19 | from .nbbase import ( | |
20 | NotebookNode, |
|
20 | NotebookNode, | |
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, |
|
21 | new_code_cell, new_text_cell, new_notebook, new_output, new_worksheet, | |
22 | new_metadata, new_author, new_heading_cell |
|
22 | new_metadata, new_author, new_heading_cell, nbformat | |
23 | ) |
|
23 | ) | |
24 |
|
24 | |||
25 | from .nbjson import reads as reads_json, writes as writes_json |
|
25 | from .nbjson import reads as reads_json, writes as writes_json |
@@ -27,7 +27,7 b' from IPython.nbformat import v2' | |||||
27 | #----------------------------------------------------------------------------- |
|
27 | #----------------------------------------------------------------------------- | |
28 |
|
28 | |||
29 | def convert_to_this_nbformat(nb, orig_version=2): |
|
29 | def convert_to_this_nbformat(nb, orig_version=2): | |
30 |
"""Convert a notebook to the v |
|
30 | """Convert a notebook to the v3 format. | |
31 |
|
31 | |||
32 | Parameters |
|
32 | Parameters | |
33 | ---------- |
|
33 | ---------- |
@@ -30,6 +30,9 b' from IPython.utils.ipstruct import Struct' | |||||
30 | # Code |
|
30 | # Code | |
31 | #----------------------------------------------------------------------------- |
|
31 | #----------------------------------------------------------------------------- | |
32 |
|
32 | |||
|
33 | # Change this when incrementing the nbformat version | |||
|
34 | nbformat = 3 | |||
|
35 | ||||
33 | class NotebookNode(Struct): |
|
36 | class NotebookNode(Struct): | |
34 | pass |
|
37 | pass | |
35 |
|
38 | |||
@@ -146,7 +149,7 b' def new_worksheet(name=None, cells=None):' | |||||
146 | def new_notebook(metadata=None, worksheets=None): |
|
149 | def new_notebook(metadata=None, worksheets=None): | |
147 | """Create a notebook by name, id and a list of worksheets.""" |
|
150 | """Create a notebook by name, id and a list of worksheets.""" | |
148 | nb = NotebookNode() |
|
151 | nb = NotebookNode() | |
149 |
nb.nbformat = |
|
152 | nb.nbformat = nbformat | |
150 | if worksheets is None: |
|
153 | if worksheets is None: | |
151 | nb.worksheets = [] |
|
154 | nb.worksheets = [] | |
152 | else: |
|
155 | else: |
@@ -20,7 +20,7 b' import re' | |||||
20 | from .rwbase import NotebookReader, NotebookWriter |
|
20 | from .rwbase import NotebookReader, NotebookWriter | |
21 | from .nbbase import ( |
|
21 | from .nbbase import ( | |
22 | new_code_cell, new_text_cell, new_worksheet, |
|
22 | new_code_cell, new_text_cell, new_worksheet, | |
23 | new_notebook, new_heading_cell |
|
23 | new_notebook, new_heading_cell, nbformat | |
24 | ) |
|
24 | ) | |
25 |
|
25 | |||
26 | #----------------------------------------------------------------------------- |
|
26 | #----------------------------------------------------------------------------- | |
@@ -151,7 +151,7 b' class PyWriter(NotebookWriter):' | |||||
151 |
|
151 | |||
152 | def writes(self, nb, **kwargs): |
|
152 | def writes(self, nb, **kwargs): | |
153 | lines = [u'# -*- coding: utf-8 -*-'] |
|
153 | lines = [u'# -*- coding: utf-8 -*-'] | |
154 |
lines.extend([u'# <nbformat> |
|
154 | lines.extend([u'# <nbformat>%i</nbformat>' % nbformat,'']) | |
155 | for ws in nb.worksheets: |
|
155 | for ws in nb.worksheets: | |
156 | for cell in ws.cells: |
|
156 | for cell in ws.cells: | |
157 | if cell.cell_type == u'code': |
|
157 | if cell.cell_type == u'code': |
@@ -4,7 +4,7 b' from base64 import encodestring' | |||||
4 | from ..nbbase import ( |
|
4 | from ..nbbase import ( | |
5 | NotebookNode, |
|
5 | NotebookNode, | |
6 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, |
|
6 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, | |
7 | new_metadata, new_author, new_heading_cell |
|
7 | new_metadata, new_author, new_heading_cell, nbformat | |
8 | ) |
|
8 | ) | |
9 |
|
9 | |||
10 | # some random base64-encoded *bytes* |
|
10 | # some random base64-encoded *bytes* | |
@@ -92,7 +92,7 b' nb0 = new_notebook(' | |||||
92 | ) |
|
92 | ) | |
93 |
|
93 | |||
94 | nb0_py = """# -*- coding: utf-8 -*- |
|
94 | nb0_py = """# -*- coding: utf-8 -*- | |
95 |
# <nbformat> |
|
95 | # <nbformat>%i</nbformat> | |
96 |
|
96 | |||
97 | # <htmlcell> |
|
97 | # <htmlcell> | |
98 |
|
98 | |||
@@ -122,6 +122,6 b' a = numpy.random.rand(100)' | |||||
122 |
|
122 | |||
123 | print a |
|
123 | print a | |
124 |
|
124 | |||
125 | """ |
|
125 | """ % nbformat | |
126 |
|
126 | |||
127 |
|
127 |
@@ -3,7 +3,7 b' from unittest import TestCase' | |||||
3 | from ..nbbase import ( |
|
3 | from ..nbbase import ( | |
4 | NotebookNode, |
|
4 | NotebookNode, | |
5 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, |
|
5 | new_code_cell, new_text_cell, new_worksheet, new_notebook, new_output, | |
6 | new_author, new_metadata, new_heading_cell |
|
6 | new_author, new_metadata, new_heading_cell, nbformat | |
7 | ) |
|
7 | ) | |
8 |
|
8 | |||
9 | class TestCell(TestCase): |
|
9 | class TestCell(TestCase): | |
@@ -102,7 +102,7 b' class TestNotebook(TestCase):' | |||||
102 | nb = new_notebook() |
|
102 | nb = new_notebook() | |
103 | self.assertEquals(nb.worksheets, []) |
|
103 | self.assertEquals(nb.worksheets, []) | |
104 | self.assertEquals(nb.metadata, NotebookNode()) |
|
104 | self.assertEquals(nb.metadata, NotebookNode()) | |
105 |
self.assertEquals(nb.nbformat, |
|
105 | self.assertEquals(nb.nbformat,nbformat) | |
106 |
|
106 | |||
107 | def test_notebook(self): |
|
107 | def test_notebook(self): | |
108 | worksheets = [new_worksheet(),new_worksheet()] |
|
108 | worksheets = [new_worksheet(),new_worksheet()] | |
@@ -110,7 +110,7 b' class TestNotebook(TestCase):' | |||||
110 | nb = new_notebook(metadata=metadata,worksheets=worksheets) |
|
110 | nb = new_notebook(metadata=metadata,worksheets=worksheets) | |
111 | self.assertEquals(nb.metadata.name,u'foo') |
|
111 | self.assertEquals(nb.metadata.name,u'foo') | |
112 | self.assertEquals(nb.worksheets,worksheets) |
|
112 | self.assertEquals(nb.worksheets,worksheets) | |
113 |
self.assertEquals(nb.nbformat, |
|
113 | self.assertEquals(nb.nbformat,nbformat) | |
114 |
|
114 | |||
115 | class TestMetadata(TestCase): |
|
115 | class TestMetadata(TestCase): | |
116 |
|
116 |
General Comments 0
You need to be logged in to leave comments.
Login now