From 1ce1654c75b1dd27f5615456b76609e308be195b Mon Sep 17 00:00:00 2001 From: arokem Date: Mon, 9 Mar 2015 12:01:28 -0700 Subject: [PATCH 1/2] RF: Update to use v4 notebooks and new IPython 3.0 API. --- pymatbridge/publish.py | 19 ++++++++----------- pymatbridge/tests/test_publish.py | 6 +++--- 2 files changed, 11 insertions(+), 14 deletions(-) diff --git a/pymatbridge/publish.py b/pymatbridge/publish.py index 3145a8f..f6d97d7 100644 --- a/pymatbridge/publish.py +++ b/pymatbridge/publish.py @@ -1,7 +1,5 @@ -try: - from IPython.nbformat import current_nbformat as nbformat -except ImportError: - import IPython.nbformat.current as nbformat +import IPython.nbformat.v4 as nbformat +from IPython.nbformat import write as nbwrite import numpy as np @@ -97,18 +95,17 @@ def lines_to_notebook(lines, name=None): # Append the notebook with loading matlab magic extension notebook_head = "import pymatbridge as pymat\n" + "ip = get_ipython()\n" \ + "pymat.load_ipython_extension(ip)" - cells.append(nbformat.new_code_cell(notebook_head, language='python')) + cells.append(nbformat.new_code_cell(notebook_head))#, language='python')) for cell_idx, cell_s in enumerate(cell_source): if cell_md[cell_idx]: - cells.append(nbformat.new_text_cell('markdown', cell_s)) + cells.append(nbformat.new_markdown_cell(cell_s)) else: cell_s.insert(0, '%%matlab\n') - cells.append(nbformat.new_code_cell(cell_s, language='matlab')) + cells.append(nbformat.new_code_cell(cell_s))#, language='matlab')) - ws = nbformat.new_worksheet(cells=cells) - notebook = nbformat.new_notebook(metadata=nbformat.new_metadata(), - worksheets=[ws]) + #ws = nbformat.new_worksheet(cells=cells) + notebook = nbformat.new_notebook(cells=cells) return notebook @@ -130,4 +127,4 @@ def convert_mfile(mfile, outfile=None): if outfile is None: outfile = mfile.split('.m')[0] + '.ipynb' with open(outfile, 'w') as fid: - nbformat.write(nb, fid, format='ipynb') + nbwrite(nb, fid) diff --git a/pymatbridge/tests/test_publish.py b/pymatbridge/tests/test_publish.py index 5c73e0f..cb3f093 100644 --- a/pymatbridge/tests/test_publish.py +++ b/pymatbridge/tests/test_publish.py @@ -36,7 +36,7 @@ def test_lines_to_notebook(): nb = publish.lines_to_notebook(lines) - npt.assert_equal(nb['worksheets'][0]['cells'][1]['source'][0], + npt.assert_equal(nb['cells'][1]['source'][0], ' This is a first line\n\n') @@ -45,7 +45,7 @@ def test_convert_mfile(): nb_file = MFILE.replace('.m', '.ipynb') with open(nb_file) as fid: nb = json.load(fid) - npt.assert_equal(nb['worksheets'][0]['cells'][1]['source'][0], + npt.assert_equal(nb['cells'][1]['source'][0], ' Experimenting with conversion from matlab to ipynb\n\n') os.remove(nb_file) @@ -55,5 +55,5 @@ def test_mfile_to_lines(): nb = publish.lines_to_notebook(lines) - npt.assert_equal(nb['worksheets'][0]['cells'][1]['source'][0], + npt.assert_equal(nb['cells'][1]['source'][0], ' Experimenting with conversion from matlab to ipynb\n\n') From 20f30274cb6754f848706a038f48fec71193f4bd Mon Sep 17 00:00:00 2001 From: arokem Date: Mon, 9 Mar 2015 12:20:50 -0700 Subject: [PATCH 2/2] BF: IPython.nbformat requires jsonschema upon import. --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 362025d..dd6961b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -24,7 +24,7 @@ before_install: - conda config --set always_yes yes - conda update conda - conda info -a - - travis_retry conda create -n test $CONDA IPython pip nose pyzmq + - travis_retry conda create -n test $CONDA IPython pip nose pyzmq jsonschema - source activate test - travis_retry pip install coveralls