This is an automated email from the ASF dual-hosted git repository.
gyeongtae pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zeppelin.git
The following commit(s) were added to refs/heads/master by this push:
new 4297661d8f [ZEPPELIN-6308] Extract hardcoded py4j values to constants
4297661d8f is described below
commit 4297661d8f15453a30a898dc9151c6ab6c181e7f
Author: YeonKyung Ryu <[email protected]>
AuthorDate: Sun Sep 7 19:44:44 2025 +0900
[ZEPPELIN-6308] Extract hardcoded py4j values to constants
### What is this PR for?
This PR extracts hardcoded py4j values to constants in Python interpreters
to improve maintainability. It creates a new PythonConstants class to
centralize py4j version and file path constants, replacing hardcoded strings
across multiple Python interpreter classes. This addresses the TODO comment
requesting to avoid hardcoded py4j values.
### What type of PR is it?
Refactoring
### Todos
* [x] - Create PythonConstants class with py4j constants
* [x] - Replace hardcoded py4j values in IPythonInterpreter
* [x] - Replace hardcoded py4j values in PythonInterpreter
* [x] - Replace hardcoded py4j values in PythonDockerInterpreter
### What is the Jira issue?
[ZEPPELIN-6308](https://issues.apache.org/jira/browse/ZEPPELIN-6308)
### How should this be tested?
### Screenshots (if appropriate)
### Questions:
* Does the license files need to update? No
* Is there breaking changes for older versions? No
* Does this needs documentation? No
Closes #5056 from celinayk/ZEPPELIN-6308.
Signed-off-by: ParkGyeongTae <[email protected]>
---
.../apache/zeppelin/python/IPythonInterpreter.java | 5 ++--
.../apache/zeppelin/python/PythonConstants.java | 34 ++++++++++++++++++++++
.../zeppelin/python/PythonDockerInterpreter.java | 3 +-
.../apache/zeppelin/python/PythonInterpreter.java | 8 +++--
4 files changed, 44 insertions(+), 6 deletions(-)
diff --git
a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
index d40cef49b8..5d352028a8 100644
--- a/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
+++ b/python/src/main/java/org/apache/zeppelin/python/IPythonInterpreter.java
@@ -178,10 +178,9 @@ public class IPythonInterpreter extends
JupyterKernelInterpreter {
protected Map<String, String> setupKernelEnv() throws IOException {
Map<String, String> envs = super.setupKernelEnv();
if (useBuiltinPy4j) {
- //TODO(zjffdu) don't do hard code on py4j here
- File py4jDestFile = new File(kernelWorkDir, "py4j-src-0.10.9.7.zip");
+ File py4jDestFile = new File(kernelWorkDir,
PythonConstants.PY4J_ZIP_FILENAME);
FileUtils.copyURLToFile(getClass().getClassLoader().getResource(
- "python/py4j-src-0.10.9.7.zip"), py4jDestFile);
+ PythonConstants.PY4J_RESOURCE_PATH), py4jDestFile);
if (additionalPythonPath != null) {
// put the py4j at the end, because additionalPythonPath may already
contain py4j.
// e.g. IPySparkInterpreter
diff --git
a/python/src/main/java/org/apache/zeppelin/python/PythonConstants.java
b/python/src/main/java/org/apache/zeppelin/python/PythonConstants.java
new file mode 100644
index 0000000000..7134c542dd
--- /dev/null
+++ b/python/src/main/java/org/apache/zeppelin/python/PythonConstants.java
@@ -0,0 +1,34 @@
+/*
+ * 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.
+ */
+
+package org.apache.zeppelin.python;
+
+/**
+ * Constants for Python interpreters
+ */
+public class PythonConstants {
+
+ // Py4j constants
+ public static final String PY4J_VERSION = "0.10.9.7";
+ public static final String PY4J_ZIP_FILENAME = "py4j-src-" + PY4J_VERSION +
".zip";
+ public static final String PY4J_RESOURCE_PATH = "python/" +
PY4J_ZIP_FILENAME;
+
+ private PythonConstants() {
+ // Utility class, prevent instantiation
+ }
+}
+
diff --git
a/python/src/main/java/org/apache/zeppelin/python/PythonDockerInterpreter.java
b/python/src/main/java/org/apache/zeppelin/python/PythonDockerInterpreter.java
index 845bb88ae7..af550dd88a 100644
---
a/python/src/main/java/org/apache/zeppelin/python/PythonDockerInterpreter.java
+++
b/python/src/main/java/org/apache/zeppelin/python/PythonDockerInterpreter.java
@@ -91,7 +91,8 @@ public class PythonDockerInterpreter extends Interpreter {
":/_zeppelin ";
// set PYTHONPATH
- String pythonPath =
".:/_python_workdir/py4j-src-0.10.9.7.zip:/_python_workdir";
+ String pythonPath = ".:/_python_workdir/" +
+ PythonConstants.PY4J_ZIP_FILENAME + ":/_python_workdir";
setPythonCommand("docker run -i --rm " +
mountPythonScript +
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 46dbf8badd..d82263f946 100644
--- a/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
+++ b/python/src/main/java/org/apache/zeppelin/python/PythonInterpreter.java
@@ -186,7 +186,10 @@ public class PythonInterpreter extends Interpreter {
copyResourceToPythonWorkDir("python/zeppelin_context.py",
"zeppelin_context.py");
copyResourceToPythonWorkDir("python/backend_zinline.py",
"backend_zinline.py");
copyResourceToPythonWorkDir("python/mpl_config.py", "mpl_config.py");
- copyResourceToPythonWorkDir("python/py4j-src-0.10.9.7.zip",
"py4j-src-0.10.9.7.zip");
+ copyResourceToPythonWorkDir(
+ PythonConstants.PY4J_RESOURCE_PATH,
+ PythonConstants.PY4J_ZIP_FILENAME);
+
}
protected boolean useIPython() {
@@ -212,7 +215,8 @@ public class PythonInterpreter extends Interpreter {
Map<String, String> env = EnvironmentUtils.getProcEnvironment();
appendToPythonPath(env, pythonWorkDir.getAbsolutePath());
if (useBuiltinPy4j) {
- appendToPythonPath(env, pythonWorkDir.getAbsolutePath() +
"/py4j-src-0.10.9.7.zip");
+ appendToPythonPath(env,
+ pythonWorkDir.getAbsolutePath() + "/" +
PythonConstants.PY4J_ZIP_FILENAME);
}
LOGGER.info("PYTHONPATH: {}", env.get("PYTHONPATH"));
return env;