You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zeppelin.apache.org by mo...@apache.org on 2018/03/04 18:26:21 UTC

zeppelin git commit: [ZEPPELIN-3284] z.getInterpreterContext().out().clear() broken in Python interpreter

Repository: zeppelin
Updated Branches:
  refs/heads/master 66dada66e -> d90716d4d


[ZEPPELIN-3284] z.getInterpreterContext().out().clear() broken in Python interpreter

### What is this PR for?

```
%python
import time
print("Hello")
time.sleep(0.5)     # in case of Ipython kernel, print may not immediately flushed and cleared.
z.getInterpreterContext().out().clear()
print("world")
```

Expected to print `world` only.
This worked in zeppelin-0.7.x and it'll be nice keep this feature in the future version.

### What type of PR is it?
Bug fix | Improvement

### What is the Jira issue?
https://issues.apache.org/jira/browse/ZEPPELIN-3284

### How should this be tested?
* First time? Setup Travis CI as described on https://zeppelin.apache.org/contribution/contributions.html#continuous-integration
* Strongly recommended: add automated unit tests for any new or changed behavior
* Outline any manual steps to test the PR here.

### Screenshots (if appropriate)

### Questions:
* Does the licenses files need update?
* Is there breaking changes for older versions?
* Does this needs documentation?

Author: Lee moon soo <mo...@apache.org>

Closes #2829 from Leemoonsoo/ZEPPELIN-3284 and squashes the following commits:

e0dcda61f [Lee moon soo] make z.getInterpreterContext().out().clear() work in  IPythonInterprete
224a2df8e [Lee moon soo] make z.getInterpreterContext().out().clear() work in PythonInterpreter


Project: http://git-wip-us.apache.org/repos/asf/zeppelin/repo
Commit: http://git-wip-us.apache.org/repos/asf/zeppelin/commit/d90716d4
Tree: http://git-wip-us.apache.org/repos/asf/zeppelin/tree/d90716d4
Diff: http://git-wip-us.apache.org/repos/asf/zeppelin/diff/d90716d4

Branch: refs/heads/master
Commit: d90716d4d00f5b83d2bd1f16cadc88118a112f74
Parents: 66dada6
Author: Lee moon soo <mo...@apache.org>
Authored: Fri Mar 2 17:42:41 2018 -0800
Committer: Lee moon soo <mo...@apache.org>
Committed: Sun Mar 4 10:26:18 2018 -0800

----------------------------------------------------------------------
 .../java/org/apache/zeppelin/python/PythonInterpreter.java     | 1 +
 python/src/main/resources/grpc/python/zeppelin_python.py       | 3 +++
 python/src/main/resources/python/zeppelin_python.py            | 2 +-
 .../org/apache/zeppelin/python/IPythonInterpreterTest.java     | 5 +++++
 .../java/org/apache/zeppelin/python/PythonInterpreterTest.java | 6 ++++++
 5 files changed, 16 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d90716d4/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
----------------------------------------------------------------------
diff --git a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
index 028f1c6..1864409 100644
--- a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
+++ b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
@@ -388,6 +388,7 @@ public class PythonInterpreter extends Interpreter implements ExecuteResultHandl
 
     zeppelinContext.setGui(context.getGui());
     zeppelinContext.setNoteGui(context.getNoteGui());
+    zeppelinContext.setInterpreterContext(context);
 
     if (!pythonscriptRunning) {
       return new InterpreterResult(Code.ERROR, "python process not running"

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d90716d4/python/src/main/resources/grpc/python/zeppelin_python.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/grpc/python/zeppelin_python.py b/python/src/main/resources/grpc/python/zeppelin_python.py
index 1a9e8af..6d7c33e 100644
--- a/python/src/main/resources/grpc/python/zeppelin_python.py
+++ b/python/src/main/resources/grpc/python/zeppelin_python.py
@@ -33,6 +33,9 @@ class PyZeppelinContext(object):
     self.javaList = gateway.jvm.java.util.ArrayList
     self.max_result = z.getMaxResult()
 
+  def getInterpreterContext(self):
+    return self.z.getInterpreterContext()
+
   def input(self, name, defaultValue=""):
     return self.z.input(name, defaultValue)
 

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d90716d4/python/src/main/resources/python/zeppelin_python.py
----------------------------------------------------------------------
diff --git a/python/src/main/resources/python/zeppelin_python.py b/python/src/main/resources/python/zeppelin_python.py
index 519d1af..f4ea2c7 100644
--- a/python/src/main/resources/python/zeppelin_python.py
+++ b/python/src/main/resources/python/zeppelin_python.py
@@ -61,7 +61,7 @@ class PyZeppelinContext(object):
     self._setup_matplotlib()
 
   def getInterpreterContext(self):
-    return self.z.getCurrentInterpreterContext()
+    return self.z.getInterpreterContext()
 
   def input(self, name, defaultValue=""):
     return self.z.input(name, defaultValue)

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d90716d4/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
----------------------------------------------------------------------
diff --git a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
index 869d390..2d5d832 100644
--- a/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/IPythonInterpreterTest.java
@@ -456,6 +456,11 @@ public class IPythonInterpreterTest {
     interpreterResultMessages = context.out.toInterpreterResultMessage();
     assertEquals(InterpreterResult.Type.TABLE, interpreterResultMessages.get(0).getType());
     assertEquals("id\tname\n1\ta\n2\tb\n3\tc\n", interpreterResultMessages.get(0).getData());
+
+    // clear output
+    context = getInterpreterContext();
+    result = interpreter.interpret("import time\nprint(\"Hello\")\ntime.sleep(0.5)\nz.getInterpreterContext().out().clear()\nprint(\"world\")\n", context);
+    assertEquals("%text world\n", context.out.getCurrentOutput().toString());
   }
 
   private static InterpreterContext getInterpreterContext() {

http://git-wip-us.apache.org/repos/asf/zeppelin/blob/d90716d4/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
----------------------------------------------------------------------
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
index 1143b9e..c0beccb 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterTest.java
@@ -123,6 +123,12 @@ public class PythonInterpreterTest implements InterpreterOutputListener {
     assertEquals(InterpreterResult.Code.SUCCESS, pythonInterpreter.interpret(pyValidCode, context).code());
   }
 
+  @Test
+  public void testOutputClear() throws InterpreterException {
+    InterpreterResult result = pythonInterpreter.interpret("print(\"Hello\")\nz.getInterpreterContext().out().clear()\nprint(\"world\")\n", context);
+    assertEquals("%text world\n", out.getCurrentOutput().toString());
+  }
+
   @Override
   public void onUpdateAll(InterpreterOutput out) {