mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-02-07 13:41:24 +00:00
ipython utils: handle ancient versions of IPython
Very old versions of IPython do not have IPython.version_info attribute that the ultls module relied on. This commit changes it to use the more standard __version__ attriute that is present in all versions.
This commit is contained in:
parent
54e89a2118
commit
97a397d5c8
@ -15,6 +15,7 @@
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
import_error_str = ''
|
import_error_str = ''
|
||||||
try:
|
try:
|
||||||
@ -31,38 +32,37 @@ except ImportError as import_error:
|
|||||||
# The current code generates notebooks version 3
|
# The current code generates notebooks version 3
|
||||||
NBFORMAT_VERSION = 3
|
NBFORMAT_VERSION = 3
|
||||||
|
|
||||||
if IPython and (IPython.version_info[0] == 2):
|
|
||||||
import IPython.kernel
|
|
||||||
import IPython.nbformat.v3
|
|
||||||
|
|
||||||
def read_notebook(notebook_in):
|
if IPython:
|
||||||
return IPython.nbformat.v3.reads_json(notebook_in) # pylint: disable=E1101
|
if StrictVersion(IPython.__version__) >= StrictVersion('3.0.0'):
|
||||||
|
import IPython.kernel
|
||||||
|
import IPython.nbformat
|
||||||
|
|
||||||
def write_notebook(notebook, fout):
|
def read_notebook(notebook_in):
|
||||||
IPython.nbformat.v3.nbjson.JSONWriter().write(notebook, fout) # pylint: disable=E1101
|
return IPython.nbformat.reads(notebook_in, NBFORMAT_VERSION) # pylint: disable=E1101
|
||||||
|
|
||||||
NotebookNode = IPython.nbformat.v3.NotebookNode # pylint: disable=E1101
|
def write_notebook(notebook, fout):
|
||||||
|
IPython.nbformat.write(notebook, fout) # pylint: disable=E1101
|
||||||
|
|
||||||
IPYTHON_NBCONVERT = ['ipython', 'nbconvert', '--to=latex', '--post=PDF']
|
NotebookNode = IPython.nbformat.NotebookNode # pylint: disable=E1101
|
||||||
|
|
||||||
elif IPython and (IPython.version_info[0] == 3):
|
IPYTHON_NBCONVERT = ['ipython', 'nbconvert', '--to=pdf']
|
||||||
import IPython.kernel
|
elif StrictVersion(IPython.__version__) >= StrictVersion('2.0.0'):
|
||||||
import IPython.nbformat
|
import IPython.kernel
|
||||||
|
import IPython.nbformat.v3
|
||||||
|
|
||||||
def read_notebook(notebook_in):
|
def read_notebook(notebook_in):
|
||||||
return IPython.nbformat.reads(notebook_in, NBFORMAT_VERSION) # pylint: disable=E1101
|
return IPython.nbformat.v3.reads_json(notebook_in) # pylint: disable=E1101
|
||||||
|
|
||||||
def write_notebook(notebook, fout):
|
def write_notebook(notebook, fout):
|
||||||
IPython.nbformat.write(notebook, fout) # pylint: disable=E1101
|
IPython.nbformat.v3.nbjson.JSONWriter().write(notebook, fout) # pylint: disable=E1101
|
||||||
|
|
||||||
NotebookNode = IPython.nbformat.NotebookNode # pylint: disable=E1101
|
NotebookNode = IPython.nbformat.v3.NotebookNode # pylint: disable=E1101
|
||||||
|
|
||||||
IPYTHON_NBCONVERT = ['ipython', 'nbconvert', '--to=pdf']
|
IPYTHON_NBCONVERT = ['ipython', 'nbconvert', '--to=latex', '--post=PDF']
|
||||||
|
else:
|
||||||
elif IPython:
|
# Unsupported IPython version
|
||||||
# Unsupported IPython version
|
import_error_str = 'Unsupported IPython version {}'.format(IPython.__version__)
|
||||||
IPython_ver_str = ".".join([str(n) for n in IPython.version_info])
|
|
||||||
import_error_str = 'Unsupported IPython version {}'.format(IPython_ver_str)
|
|
||||||
|
|
||||||
|
|
||||||
def parse_valid_output(msg):
|
def parse_valid_output(msg):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user