1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-02-21 20:38:57 +00:00

Merge pull request #73 from ep1cman/ipython4

ipython: Updated to work with the latest ipython version
This commit is contained in:
setrofim 2016-01-12 14:37:37 +00:00
commit 1ef7bb4e93

View File

@ -18,7 +18,7 @@ import os
import subprocess import subprocess
from distutils.version import StrictVersion from distutils.version import StrictVersion
# pylint: disable=wrong-import-position # pylint: disable=wrong-import-position,ungrouped-imports
import_error_str = '' import_error_str = ''
try: try:
import IPython import IPython
@ -36,14 +36,29 @@ NBFORMAT_VERSION = 3
if IPython: if IPython:
if StrictVersion('4.0.0') > StrictVersion(IPython.__version__) >= StrictVersion('3.0.0'): if StrictVersion('5.0.0') > StrictVersion(IPython.__version__) >= StrictVersion('4.0.0'):
import IPython.kernel import nbformat
from jupyter_client.manager import KernelManager
def read_notebook(notebook_in): # pylint: disable=function-redefined
return nbformat.reads(notebook_in, NBFORMAT_VERSION) # pylint: disable=E1101
def write_notebook(notebook, fout): # pylint: disable=function-redefined
nbformat.write(notebook, fout) # pylint: disable=E1101
NotebookNode = nbformat.NotebookNode # pylint: disable=E1101
IPYTHON_NBCONVERT_HTML = ['jupyter', 'nbconvert', '--to html']
IPYTHON_NBCONVERT_PDF = ['jupyter', 'nbconvert', '--to pdf']
elif StrictVersion('4.0.0') > StrictVersion(IPython.__version__) >= StrictVersion('3.0.0'):
from IPython.kernel import KernelManager
import IPython.nbformat import IPython.nbformat
def read_notebook(notebook_in): def read_notebook(notebook_in): # pylint: disable=function-redefined
return IPython.nbformat.reads(notebook_in, NBFORMAT_VERSION) # pylint: disable=E1101 return IPython.nbformat.reads(notebook_in, NBFORMAT_VERSION) # pylint: disable=E1101
def write_notebook(notebook, fout): def write_notebook(notebook, fout): # pylint: disable=function-redefined
IPython.nbformat.write(notebook, fout) # pylint: disable=E1101 IPython.nbformat.write(notebook, fout) # pylint: disable=E1101
NotebookNode = IPython.nbformat.NotebookNode # pylint: disable=E1101 NotebookNode = IPython.nbformat.NotebookNode # pylint: disable=E1101
@ -51,13 +66,13 @@ if IPython:
IPYTHON_NBCONVERT_HTML = ['ipython', 'nbconvert', '--to=html'] IPYTHON_NBCONVERT_HTML = ['ipython', 'nbconvert', '--to=html']
IPYTHON_NBCONVERT_PDF = ['ipython', 'nbconvert', '--to=pdf'] IPYTHON_NBCONVERT_PDF = ['ipython', 'nbconvert', '--to=pdf']
elif StrictVersion('3.0.0') > StrictVersion(IPython.__version__) >= StrictVersion('2.0.0'): elif StrictVersion('3.0.0') > StrictVersion(IPython.__version__) >= StrictVersion('2.0.0'):
import IPython.kernel from IPython.kernel import KernelManager
import IPython.nbformat.v3 import IPython.nbformat.v3
def read_notebook(notebook_in): def read_notebook(notebook_in): # pylint: disable=function-redefined
return IPython.nbformat.v3.reads_json(notebook_in) # pylint: disable=E1101 return IPython.nbformat.v3.reads_json(notebook_in) # pylint: disable=E1101
def write_notebook(notebook, fout): def write_notebook(notebook, fout): # pylint: disable=function-redefined
IPython.nbformat.v3.nbjson.JSONWriter().write(notebook, fout) # pylint: disable=E1101 IPython.nbformat.v3.nbjson.JSONWriter().write(notebook, fout) # pylint: disable=E1101
NotebookNode = IPython.nbformat.v3.NotebookNode # pylint: disable=E1101 NotebookNode = IPython.nbformat.v3.NotebookNode # pylint: disable=E1101
@ -127,8 +142,7 @@ def run_cell(kernel_client, cell):
def run_notebook(notebook): def run_notebook(notebook):
"""Run the notebook""" """Run the notebook"""
kernel_manager = KernelManager()
kernel_manager = IPython.kernel.KernelManager()
kernel_manager.start_kernel(stderr=open(os.devnull, 'w')) kernel_manager.start_kernel(stderr=open(os.devnull, 'w'))
kernel_client = kernel_manager.client() kernel_client = kernel_manager.client()
kernel_client.start_channels() kernel_client.start_channels()