mirror of
https://github.com/ARM-software/workload-automation.git
synced 2025-09-02 19:32:34 +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:
@@ -48,28 +48,13 @@ elif IPython:
|
|||||||
import_error_str = 'Unsupported IPython version {}'.format(IPython_ver_str)
|
import_error_str = 'Unsupported IPython version {}'.format(IPython_ver_str)
|
||||||
|
|
||||||
|
|
||||||
def run_cell(kernel_client, cell):
|
def parse_valid_output(msg):
|
||||||
"""Run a cell of a notebook in an ipython kernel and return its output"""
|
"""Parse a valid result from an execution of a cell in an ipython kernel"""
|
||||||
kernel_client.execute(cell.input)
|
|
||||||
|
|
||||||
input_acknowledged = False
|
|
||||||
outs = []
|
|
||||||
while True:
|
|
||||||
msg = kernel_client.get_iopub_msg()
|
|
||||||
|
|
||||||
msg_type = msg["msg_type"]
|
msg_type = msg["msg_type"]
|
||||||
content = msg["content"]
|
content = msg["content"]
|
||||||
out = NotebookNode(output_type=msg_type)
|
out = NotebookNode(output_type=msg_type)
|
||||||
|
|
||||||
if msg_type == "status":
|
if msg_type == "stream":
|
||||||
if content["execution_state"] == "idle" and input_acknowledged:
|
|
||||||
break
|
|
||||||
else:
|
|
||||||
continue
|
|
||||||
elif msg_type == "pyin":
|
|
||||||
input_acknowledged = True
|
|
||||||
continue
|
|
||||||
elif msg_type == "stream":
|
|
||||||
out.stream = content["name"]
|
out.stream = content["name"]
|
||||||
out.text = content["data"]
|
out.text = content["data"]
|
||||||
elif msg_type in ("display_data", "pyout"):
|
elif msg_type in ("display_data", "pyout"):
|
||||||
@@ -86,6 +71,25 @@ def run_cell(kernel_client, cell):
|
|||||||
else:
|
else:
|
||||||
raise ValueError("Unknown msg_type {}".format(msg_type))
|
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)
|
outs.append(out)
|
||||||
|
|
||||||
return outs
|
return outs
|
||||||
|
Reference in New Issue
Block a user