Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
19 changes: 8 additions & 11 deletions pymatbridge/publish.py
Original file line number Diff line number Diff line change
@@ -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


Expand Down Expand Up @@ -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


Expand All @@ -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)
6 changes: 3 additions & 3 deletions pymatbridge/tests/test_publish.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')


Expand All @@ -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)

Expand All @@ -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')