diff --git a/swift_kernel.py b/swift_kernel.py index 96b31a6..c1c1468 100755 --- a/swift_kernel.py +++ b/swift_kernel.py @@ -65,6 +65,13 @@ class SuccessWithValue(ExecutionResultSuccess): def __init__(self, result): self.result = result # SBValue + """A description of the value, e.g. + (Int) $R0 = 64""" + def value_description(self): + stream = lldb.SBStream() + self.result.GetDescription(stream) + return stream.GetData() + def __repr__(self): return 'SuccessWithValue(result=%s, description=%s)' % ( repr(self.result), repr(self.result.description)) @@ -294,7 +301,7 @@ def _init_int_bitwidth(self): if not isinstance(result, SuccessWithValue): raise Exception('Expected value from Int.bitWidth, but got: %s' % result) - self._int_bitwidth = int(result.result.description) + self._int_bitwidth = int(result.result.GetData().GetSignedInt32(lldb.SBError(), 0)) def _init_sigint_handler(self): self.sigint_handler = SIGINTHandler(self) @@ -794,7 +801,7 @@ def is_valid_dependency(path): raise PackageInstallException( 'Install Error: dlopen error: %s' % \ str(dynamic_load_result)) - if dynamic_load_result.result.description.strip() == 'nil': + if dynamic_load_result.value_description().endswith('nil'): raise PackageInstallException('Install Error: dlopen error. Run ' '`String(cString: dlerror())` to see ' 'the error message.') @@ -976,10 +983,11 @@ def do_execute(self, code, silent, store_history=True, # Send values/errors and status to the client. if isinstance(result, SuccessWithValue): + # TODO(#112): Make this show expression values again. self.send_response(self.iopub_socket, 'execute_result', { 'execution_count': self.execution_count, 'data': { - 'text/plain': result.result.description + 'text/plain': 'Use `print()` to show values.\n' }, 'metadata': {} }) diff --git a/test/tests/kernel_tests.py b/test/tests/kernel_tests.py index 0cbbc29..06e6c9f 100644 --- a/test/tests/kernel_tests.py +++ b/test/tests/kernel_tests.py @@ -14,7 +14,7 @@ class SwiftKernelTests(jupyter_kernel_test.KernelTests): code_hello_world = 'print("hello, world!")' code_execute_result = [ - {'code': 'let x = 2; x', 'result': '2\n'} + {'code': 'let x = 2; x', 'result': 'Use `print()` to show values.\n'}, ] code_generate_error = 'varThatIsntDefined' @@ -265,6 +265,17 @@ def test_swift_clear_output(self): }, }) + def test_show_tensor(self): + reply, output_msgs = self.execute_helper(code=""" + import TensorFlow + Tensor([1, 2, 3]) + """) + self.assertEqual(reply['content']['status'], 'ok') + if 'data' in output_msgs[0]['content']: + self.assertIn( + "Use `print()` to show values", + output_msgs[0]['content']['data']['text/plain']) + # Class for tests that need their own kernel. (`SwiftKernelTestsBase` uses one # kernel for all the tests.)