|
|
|
@ -33,6 +33,7 @@ import java.nio.file.Files;
|
|
|
|
|
import java.nio.file.Paths; |
|
|
|
|
import java.util.List; |
|
|
|
|
import java.util.function.Consumer; |
|
|
|
|
import java.util.regex.Pattern; |
|
|
|
|
|
|
|
|
|
import org.slf4j.Logger; |
|
|
|
|
import org.slf4j.LoggerFactory; |
|
|
|
@ -52,6 +53,8 @@ public class PythonCommandExecutor extends AbstractCommandExecutor {
|
|
|
|
|
*/ |
|
|
|
|
public static final String PYTHON = "python"; |
|
|
|
|
|
|
|
|
|
private static final Pattern PYTHON_PATH_PATTERN = Pattern.compile("/bin/python[\\d.]*$"); |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* constructor |
|
|
|
|
* |
|
|
|
@ -143,4 +146,34 @@ public class PythonCommandExecutor extends AbstractCommandExecutor {
|
|
|
|
|
return null; |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Gets the command path to which Python can execute |
|
|
|
|
* @return python command path |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
protected String commandInterpreter() { |
|
|
|
|
String pythonHome = getPythonHome(taskRequest.getEnvFile()); |
|
|
|
|
return getPythonCommand(pythonHome); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* get python command |
|
|
|
|
* |
|
|
|
|
* @param pythonHome python home |
|
|
|
|
* @return python command |
|
|
|
|
*/ |
|
|
|
|
public static String getPythonCommand(String pythonHome) { |
|
|
|
|
if (StringUtils.isEmpty(pythonHome)) { |
|
|
|
|
return PYTHON; |
|
|
|
|
} |
|
|
|
|
File file = new File(pythonHome); |
|
|
|
|
if (file.exists() && file.isFile()) { |
|
|
|
|
return pythonHome; |
|
|
|
|
} |
|
|
|
|
if (PYTHON_PATH_PATTERN.matcher(pythonHome).find()) { |
|
|
|
|
return pythonHome; |
|
|
|
|
} |
|
|
|
|
return Paths.get(pythonHome, "/bin/python").toString(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
} |
|
|
|
|