Skip to content

Commit

Permalink
code reivew fix
Browse files Browse the repository at this point in the history
  • Loading branch information
“v_kkhuang” committed Nov 12, 2024
1 parent 926006e commit 9ac2648
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,6 @@ public class Constants {

public static final CommonVars<String> PYTHON_COMMAND =
CommonVars.apply("linkis.execution.command.python.version", "python3");
public static final CommonVars<String> PYTHON_PATH =
CommonVars.apply("linkis.python3.path", "/appcom/Install/anaconda3/bin/python");
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ public class UdfUtils {
private static final Logger logger = LoggerFactory.getLogger(UdfUtils.class);
private static Set<String> moduleSet = new HashSet<>();

private static final String setuppyFileName = "setup.py";
private static final String pyprojecttomlFileName = "pyproject.toml";

/**
* 从 tar.gz 文件中查找PKG-INFO文件,并获取其需要打包的文件夹名称
*
Expand Down Expand Up @@ -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);
Expand All @@ -207,10 +211,11 @@ public static List<String> 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;
}
}
Expand All @@ -226,7 +231,7 @@ public static List<String> getInstallRequestPythonModules(MultipartFile file) th
return modules;
}

public static List<String> extractDependencies(String content) {
public static List<String> extractDependencies(String content, String name) {
String trim =
content
.replaceAll("#.*?\\n", "")
Expand All @@ -236,15 +241,19 @@ public static List<String> extractDependencies(String content) {
.trim();
List<String> 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) {
Expand All @@ -261,7 +270,7 @@ public static List<String> extractDependencies(String content) {
}
}
if (StringUtils.isNotBlank(pkg)) {
modules.add(pkg);
modules.add(pkg.toLowerCase());
}
}
return modules;
Expand Down

0 comments on commit 9ac2648

Please sign in to comment.