diff --git a/python/src/main/resources/bootstrap.py b/python/src/main/resources/bootstrap.py
index 0290c5f9509..09e51e31cca 100644
--- a/python/src/main/resources/bootstrap.py
+++ b/python/src/main/resources/bootstrap.py
@@ -33,76 +33,78 @@ def intHandler(signum, frame): # Set the signal handler
signal.signal(signal.SIGINT, intHandler)
-
def help():
- print ('%html')
- print ('
Python Interpreter help
')
- print ('Python 2 & 3 compatibility
')
- print ('The interpreter is compatible with Python 2 & 3.
')
- print ('To change Python version, ')
- print ('change in the interpreter configuration the python to the ')
- print ('desired version (example : python=/usr/bin/python3)
')
- print ('Python modules
')
- print ('The interpreter can use all modules already installed ')
- print ('(with pip, easy_install, etc)
')
- print ('Forms
')
- print ('You must install py4j in order to use '
- 'the form feature (pip install py4j)')
- print ('Input form
')
- print ('print (z.input("f1","defaultValue"))')
- print ('Selection form
')
- print ('print(z.select("f2", [("o1","1"), ("o2","2")],2))')
- print ('Checkbox form
')
- print (' print("".join(z.checkbox("f3", [("o1","1"), '
- '("o2","2")],["1"])))')
- print ('Matplotlib graph
')
- print ('The interpreter can display matplotlib graph with ')
- print ('the function z.show()
')
- print (' You need to already have matplotlib module installed ')
- print ('to use this functionality !
')
- print ('''import matplotlib.pyplot as plt
-plt.figure()
-(.. ..)
-z.show(plt)
-plt.close()
-
''')
- print ('
z.show function can take optional parameters ')
- print ('to adapt graph width and height
')
- print ("example :")
- print ('''
z.show(plt,width='50px')
-z.show(plt,height='150px')
''')
- print ('Pandas DataFrame
')
- print (' You need to have Pandas module installed ')
- print ('to use this functionality (pip install pandas) !
')
- print ("""
-The interpreter can visualize Pandas DataFrame
-with the function z.show()
-
-import pandas as pd
-df = pd.read_csv("bank.csv", sep=";")
-z.show(df)
-
-""")
- print ('SQL over Pandas DataFrame
')
- print (' You need to have Pandas&Pandasql modules installed ')
- print ('to use this functionality (pip install pandas pandasql) !
')
- print ("""
-Python interpreter group includes %sql interpreter that can query
-Pandas DataFrames using SQL and visualize results using Zeppelin Table Display System
-
-
-%python
-import pandas as pd
-df = pd.read_csv("bank.csv", sep=";")
-
-
-
-
-%python.sql
-%sql
-SELECT * from df LIMIT 5
-
-""")
+ print("""%html
+ Python Interpreter help
+
+ Python 2 & 3 compatibility
+ The interpreter is compatible with Python 2 & 3.
+ To change Python version,
+ change in the interpreter configuration the python to the
+ desired version (example : python=/usr/bin/python3)
+
+ Python modules
+ The interpreter can use all modules already installed
+ (with pip, easy_install, etc)
+
+ Forms
+ You must install py4j in order to use
+ the form feature (pip install py4j)
+ Input form
+ print (z.input("f1","defaultValue"))
+ Selection form
+ print(z.select("f2", [("o1","1"), ("o2","2")],2))
+ Checkbox form
+ print("".join(z.checkbox("f3", [("o1","1"), ("o2","2")],["1"])))')
+
+ Matplotlib graph
+ The interpreter can display matplotlib graph with
+ the function z.show()
+ You need to already have matplotlib module installed
+ to use this functionality !
+ import matplotlib.pyplot as plt
+ plt.figure()
+ (.. ..)
+ z.show(plt)
+ plt.close()
+
+
z.show function can take optional parameters
+ to adapt graph width and height
+ example :
+
z.show(plt,width='50px
+ z.show(plt,height='150px')
+
+ Pandas DataFrame
+ You need to have Pandas module installed
+ to use this functionality (pip install pandas) !
+ The interpreter can visualize Pandas DataFrame
+ with the function z.show()
+
+ import pandas as pd
+ df = pd.read_csv("bank.csv", sep=";")
+ z.show(df)
+
+
+ SQL over Pandas DataFrame
+ You need to have Pandas&Pandasql modules installed
+ to use this functionality (pip install pandas pandasql) !
+
+ Python interpreter group includes %sql interpreter that can query
+ Pandas DataFrames using SQL and visualize results using Zeppelin Table Display System
+
+
+ %python
+ import pandas as pd
+ df = pd.read_csv("bank.csv", sep=";")
+
+
+
+ %python.sql
+ %sql
+ SELECT * from df LIMIT 5
+
+
+ """)
class PyZeppelinContext(object):
@@ -112,18 +114,17 @@ class PyZeppelinContext(object):
errorMsg = "You must install py4j Python module " \
"(pip install py4j) to use Zeppelin dynamic forms features"
- def __init__(self, zc):
- self.z = zc
+ def __init__(self):
self.max_result = 1000
def input(self, name, defaultValue=""):
- print (self.errorMsg)
+ print(self.errorMsg)
def select(self, name, options, defaultValue=""):
- print (self.errorMsg)
+ print(self.errorMsg)
def checkbox(self, name, options, defaultChecked=[]):
- print (self.errorMsg)
+ print(self.errorMsg)
def show(self, p, **kwargs):
if hasattr(p, '__name__') and p.__name__ == "matplotlib.pyplot":
@@ -172,4 +173,4 @@ def show_matplotlib(self, p, width="100%", height="100%", **kwargs):
img.close()
-z = PyZeppelinContext("")
+z = PyZeppelinContext()
diff --git a/python/src/main/resources/bootstrap_input.py b/python/src/main/resources/bootstrap_input.py
index d15b93ad8c7..e006816256c 100644
--- a/python/src/main/resources/bootstrap_input.py
+++ b/python/src/main/resources/bootstrap_input.py
@@ -25,11 +25,11 @@
class Py4jZeppelinContext(PyZeppelinContext):
"""A context impl that uses Py4j to communicate to JVM
"""
- def __init__(self, zc):
- super(Py4jZeppelinContext, self).__init__(zc)
+ def __init__(self, z):
+ self.z = z
self.paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
self.javaList = gateway.jvm.java.util.ArrayList
- self.max_result = 1000 #TODO(bzz): read `zeppelin.python.maxResult` from JVM
+ self.max_result = self.z.getMaxResult()
def input(self, name, defaultValue=""):
return self.z.getGui().input(name, defaultValue)
diff --git a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java
index 15787fdce46..38b46e71ca8 100644
--- a/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java
+++ b/python/src/test/java/org/apache/zeppelin/python/PythonInterpreterWithPythonInstalledTest.java
@@ -42,7 +42,7 @@
public class PythonInterpreterWithPythonInstalledTest {
@Test
- public void badSqlSyntaxFails() {
+ public void badPythonSyntaxFails() {
//given
PythonInterpreter realPython = new PythonInterpreter(
PythonInterpreterTest.getPythonTestProperties());
@@ -58,4 +58,21 @@ public void badSqlSyntaxFails() {
assertTrue(ret.message().length() > 0);
}
+ @Test
+ public void goodPythonSyntaxRuns() {
+ //given
+ PythonInterpreter realPython = new PythonInterpreter(
+ PythonInterpreterTest.getPythonTestProperties());
+ realPython.open();
+
+ //when
+ InterpreterResult ret = realPython.interpret("help()", null);
+
+ //then
+ assertNotNull("Interpreter returned 'null'", ret);
+ //System.out.println("\nInterpreter response: \n" + ret.message());
+ assertEquals(InterpreterResult.Code.SUCCESS, ret.code());
+ assertTrue(ret.message().length() > 0);
+ }
+
}