From 7f41a96fc102110366738b59c437884e19ae6b8e Mon Sep 17 00:00:00 2001 From: xiangzihao <460888207@qq.com> Date: Sat, 16 Apr 2022 18:57:33 +0800 Subject: [PATCH] [Fix-9525] [Worker] Environment did not work as expected (#9527) * fix #9525 * change to ${PYTHON_HOME} * remove import * fix ut error --- .../dolphinscheduler/plugin/task/python/PythonTask.java | 6 ++---- .../dolphinscheduler/plugin/task/python/PythonTaskTest.java | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java index 1df388f756..c153847b18 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/main/java/org/apache/dolphinscheduler/plugin/task/python/PythonTask.java @@ -238,10 +238,8 @@ public class PythonTask extends AbstractTaskExecutor { private String buildPythonExecuteCommand(String pythonFile) { Preconditions.checkNotNull(pythonFile, "Python file cannot be null"); - String pythonHome = System.getenv(PYTHON_HOME); - if (StringUtils.isEmpty(pythonHome)) { - return DEFAULT_PYTHON_VERSION + " " + pythonFile; - } + String pythonHome = String.format("${%s}", PYTHON_HOME); + return pythonHome + " " + pythonFile; } diff --git a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java index 08c5e0d8cf..7df5342179 100644 --- a/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java +++ b/dolphinscheduler-task-plugin/dolphinscheduler-task-python/src/test/java/org/apache/dolphinscheduler/plugin/task/python/PythonTaskTest.java @@ -29,7 +29,7 @@ public class PythonTaskTest { String methodName = "buildPythonExecuteCommand"; String pythonFile = "test.py"; String result1 = Whitebox.invokeMethod(pythonTask, methodName, pythonFile); - Assert.assertEquals("python test.py", result1); + Assert.assertEquals("${PYTHON_HOME} test.py", result1); } private PythonTask createPythonTask() {