Browse Source

[Fix-9525] [Worker] Environment did not work as expected (#9527)

* fix #9525

* change to ${PYTHON_HOME}

* remove import

* fix ut error
xiangzihao 3 years ago
parent
commit
7f41a96fc1

+ 2 - 4
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;
     }
 

+ 1 - 1
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() {