From 9ac26484df5c20761176611d03b23ad8bde38ffc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9Cv=5Fkkhuang=E2=80=9D?= <“420895376@qq.com”> Date: Tue, 12 Nov 2024 15:45:36 +0800 Subject: [PATCH] code reivew fix --- .../org/apache/linkis/udf/conf/Constants.java | 2 ++ .../org/apache/linkis/udf/utils/UdfUtils.java | 33 ++++++++++++------- 2 files changed, 23 insertions(+), 12 deletions(-) diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/conf/Constants.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/conf/Constants.java index 0f973780ee..ad2692333d 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/conf/Constants.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/conf/Constants.java @@ -31,4 +31,6 @@ public class Constants { public static final CommonVars PYTHON_COMMAND = CommonVars.apply("linkis.execution.command.python.version", "python3"); + public static final CommonVars PYTHON_PATH = + CommonVars.apply("linkis.python3.path", "/appcom/Install/anaconda3/bin/python"); } diff --git a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java index 885651fe73..714e5e17ed 100644 --- a/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java +++ b/linkis-public-enhancements/linkis-udf-service/src/main/java/org/apache/linkis/udf/utils/UdfUtils.java @@ -50,6 +50,9 @@ public class UdfUtils { private static final Logger logger = LoggerFactory.getLogger(UdfUtils.class); private static Set moduleSet = new HashSet<>(); + private static final String setuppyFileName = "setup.py"; + private static final String pyprojecttomlFileName = "pyproject.toml"; + /** * 从 tar.gz 文件中查找PKG-INFO文件,并获取其需要打包的文件夹名称 * @@ -186,6 +189,7 @@ public static Boolean checkModuleIsExistEnv(String module) { (new String[] { Constants.PYTHON_COMMAND.getValue(), Configuration.getLinkisHome() + "/admin/" + "check_modules.py", + Constants.PYTHON_PATH.getValue(), module })); return Boolean.parseBoolean(exec); @@ -207,10 +211,11 @@ public static List getInstallRequestPythonModules(MultipartFile file) th new TarArchiveInputStream(new GzipCompressorInputStream(file.getInputStream()))) { TarArchiveEntry entry; while ((entry = tarInput.getNextTarEntry()) != null) { - if (entry.getName().endsWith("setup.py") || entry.getName().endsWith("pyproject.toml")) { + if (entry.getName().endsWith(setuppyFileName) + || entry.getName().endsWith(pyprojecttomlFileName)) { findSetup = 1; String content = IOUtils.toString(tarInput, StandardCharsets.UTF_8); - modules = extractDependencies(content); + modules = extractDependencies(content, entry.getName()); break; } } @@ -226,7 +231,7 @@ public static List getInstallRequestPythonModules(MultipartFile file) th return modules; } - public static List extractDependencies(String content) { + public static List extractDependencies(String content, String name) { String trim = content .replaceAll("#.*?\\n", "") @@ -236,15 +241,19 @@ public static List extractDependencies(String content) { .trim(); List modules = new ArrayList<>(); String moduleStr = ""; - Matcher setupMatcher = - Pattern.compile("install_requires=\\[(.*?)\\]", Pattern.DOTALL).matcher(trim); - if (setupMatcher.find()) { - moduleStr = setupMatcher.group(1); + if (name.endsWith(setuppyFileName)) { + Matcher setupMatcher = + Pattern.compile("install_requires=\\[(.*?)\\]", Pattern.DOTALL).matcher(trim); + if (setupMatcher.find()) { + moduleStr = setupMatcher.group(1); + } } - Matcher pyprojectMatcher = - Pattern.compile("dependencies=\\[(.*?)\\]", Pattern.DOTALL).matcher(trim); - if (pyprojectMatcher.find()) { - moduleStr = pyprojectMatcher.group(1); + if (name.endsWith(pyprojecttomlFileName)) { + Matcher pyprojectMatcher = + Pattern.compile("dependencies=\\[(.*?)\\]", Pattern.DOTALL).matcher(trim); + if (pyprojectMatcher.find()) { + moduleStr = pyprojectMatcher.group(1); + } } String[] packages = moduleStr.split(","); for (String pkg : packages) { @@ -261,7 +270,7 @@ public static List extractDependencies(String content) { } } if (StringUtils.isNotBlank(pkg)) { - modules.add(pkg); + modules.add(pkg.toLowerCase()); } } return modules;