mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
### What is this PR for? Adding a python 2 &3 interpreter. It's a basic implementation (no py4j for example), with a java ProcessBuilder object used to instantiate a python REPL. The interpreter doesn't bring it own python binary but uses the python specified by python.path configutation. Thus, you can still use your specific installed python modules (scikit-learn, matplotlib...) and the interpreter is able to work with python 2 & 3 without change. I had a python helper function (zeppelin_show() ) to easily display matplotlib graph as SVG. ### What type of PR is it? [Feature] ### Todos * [x] - Code review * [x] - Improve bootstrap.py : choose available helper functions and their names * [x] - Unit / IT tests ? * [x] documentation updates needed, that AhyoungRyu pointed out * [X] LICENSE needs to be updated to include all non-apache licensed dependencies (i.e AFAIK Py4j is BSD ) in bin-license * [x] double-check that code formatting conforms project style guide * [x] the branch need to be rebased on latest master. ### What is the Jira issue? [ZEPPELIN-502](https://issues.apache.org/jira/browse/ZEPPELIN-502?jql=project%20%3D%20ZEPPELIN%20AND%20text%20~%20%22python%22) ### How should this be tested? 1. In interpreter screen, in Python section, specify in python.path the python binary you want to use 2. In a paragraph, you can use the interpreter with **_%python_**. Calling help() will describe you the interpreter functionnalities. 3. Install py4j (pip install py4j) if you want to use input form ### Screenshots     ### Questions: * Does the licenses files need update? Yes, only bin-license (py4j) * Is there breaking changes for older versions? No * Does this needs documentation? Yes Author: Hervé RIVIERE <hriviere@users.noreply.github.com> Closes #869 from hriviere/PR_interpreter_python and squashes the following commits:80b6e75[Hervé RIVIERE] [ZEPPELIN-502] move BSD py4j license to zeppelin-distribution/src/bin_license/licensea4b82a5[Hervé RIVIERE] [ZEPPELIN-502]Improving doc following @AhyoungRyu review3252353[Hervé RIVIERE] [ZEPPELIN-502] Formatting code to respect project convention54ec4f1[Hervé RIVIERE] [ZEPPELIN-502]Improving doc following @AhyoungRyu review6a831bc[Hervé RIVIERE] [ZEPPELIN-502] Add BSD py4j license11e1b9c[Hervé RIVIERE] [ZEPPELIN-502] minor changes in python.mde5d0bdb[Hervé RIVIERE] [ZEPPELIN-502] change PYTHON_PATH to ZEPPELIN_PYTHONc62ac98[Hervé RIVIERE] [ZEPPELIN-502] Improve python.md5008125[Hervé RIVIERE] [ZEPPELIN-502] Improve python.md with features not yet supported and technical description7d533e1[Hervé RIVIERE] [ZEPPELIN-502] Add tests and reformating code to help tests writingfecaf25[Hervé RIVIERE] [ZEPPELIN-502] Rename python.path to python and default from /usr/bin/python to python02d1320[Hervé RIVIERE] [ZEPPELIN-502] Input form, change from simple input form to native (pyspark syntax)60d2956[Hervé RIVIERE] [ZEPPELIN-502] Indent as pep8 convention9bdb192[Hervé RIVIERE] [ZEPPELIN-502] Add python.md to _navigation.html7142aa5[Hervé RIVIERE] [ZEPPELIN-502] Catch exception in logger.error1a86ad7[Hervé RIVIERE] [ZEPPELIN-502] Python interpreter group
51 lines
2.1 KiB
Python
51 lines
2.1 KiB
Python
# Licensed to the Apache Software Foundation (ASF) under one or more
|
|
# contributor license agreements. See the NOTICE file distributed with
|
|
# this work for additional information regarding copyright ownership.
|
|
# The ASF licenses this file to You under the Apache License, Version 2.0
|
|
# (the "License"); you may not use this file except in compliance with
|
|
# the License. You may obtain a copy of the License at
|
|
#
|
|
# http://www.apache.org/licenses/LICENSE-2.0
|
|
#
|
|
# Unless required by applicable law or agreed to in writing, software
|
|
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
# See the License for the specific language governing permissions and
|
|
# limitations under the License.
|
|
|
|
|
|
from py4j.java_gateway import JavaGateway
|
|
from py4j.java_gateway import java_import, JavaGateway, GatewayClient
|
|
|
|
client = GatewayClient(port=%PORT%)
|
|
gateway = JavaGateway(client)
|
|
java_import(gateway.jvm, "org.apache.zeppelin.display.Input")
|
|
|
|
|
|
class PyZeppelinContext():
|
|
paramOption = gateway.jvm.org.apache.zeppelin.display.Input.ParamOption
|
|
javaList = gateway.jvm.java.util.ArrayList
|
|
def __init__(self, zc):
|
|
self.z = zc
|
|
def input(self, name, defaultValue=""):
|
|
return self.z.getGui().input(name, defaultValue)
|
|
def select(self, name, options, defaultValue=""):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
return self.z.getGui().select(name, defaultValue, javaOptions)
|
|
def checkbox(self, name, options, defaultChecked=[]):
|
|
javaOptions = gateway.new_array(self.paramOption, len(options))
|
|
i = 0
|
|
for tuple in options:
|
|
javaOptions[i] = self.paramOption(tuple[0], tuple[1])
|
|
i += 1
|
|
javaDefaultCheck = self.javaList()
|
|
for check in defaultChecked:
|
|
javaDefaultCheck.append(check)
|
|
return self.z.getGui().checkbox(name, javaDefaultCheck, javaOptions)
|
|
|
|
|
|
z = PyZeppelinContext(gateway.entry_point)
|