1
0
mirror of https://github.com/ARM-software/workload-automation.git synced 2025-04-20 17:50:49 +01:00

Factor out the parsing of a valid cell run in the generic ipython implementation

run_cell() becomes more complicated when we add ipython version 3
support which upsets pylint because there are "too many
branches (15/12)".  Factor out part of the function to make pylint
happy.
This commit is contained in:
Javi Merino 2015-04-17 18:50:31 +01:00
parent 2b04cb38d9
commit d12f5c65e1

View File

@ -48,28 +48,13 @@ elif IPython:
import_error_str = 'Unsupported IPython version {}'.format(IPython_ver_str)
def run_cell(kernel_client, cell):
"""Run a cell of a notebook in an ipython kernel and return its output"""
kernel_client.execute(cell.input)
input_acknowledged = False
outs = []
while True:
msg = kernel_client.get_iopub_msg()
def parse_valid_output(msg):
"""Parse a valid result from an execution of a cell in an ipython kernel"""
msg_type = msg["msg_type"]
content = msg["content"]
out = NotebookNode(output_type=msg_type)
if msg_type == "status":
if content["execution_state"] == "idle" and input_acknowledged:
break
else:
continue
elif msg_type == "pyin":
input_acknowledged = True
continue
elif msg_type == "stream":
if msg_type == "stream":
out.stream = content["name"]
out.text = content["data"]
elif msg_type in ("display_data", "pyout"):
@ -86,6 +71,25 @@ def run_cell(kernel_client, cell):
else:
raise ValueError("Unknown msg_type {}".format(msg_type))
return out
def run_cell(kernel_client, cell):
"""Run a cell of a notebook in an ipython kernel and return its output"""
kernel_client.execute(cell.input)
input_acknowledged = False
outs = []
while True:
msg = kernel_client.get_iopub_msg()
if msg["msg_type"] == "status":
if msg["content"]["execution_state"] == "idle" and input_acknowledged:
break
elif msg["msg_type"] == "pyin":
input_acknowledged = True
else:
out = parse_valid_output(msg)
outs.append(out)
return outs