Skip to content

Commit

Permalink
fix: results of pip show are not properly parsed
Browse files Browse the repository at this point in the history
  • Loading branch information
xieshenzh committed Oct 18, 2023
1 parent f060dd7 commit ee60826
Show file tree
Hide file tree
Showing 2 changed files with 1,982 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/main/java/com/redhat/exhort/utils/PythonControllerBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ private List<Map<String, Object>> getDependenciesImpl(String pathToRequirements,
String[] deps = freeze.split(System.lineSeparator());
String depNames = Arrays.stream(deps).map(PythonControllerBase::getDependencyName).collect(Collectors.joining(" "));
String pipShowOutput = Operations.runProcessGetOutput(pythonEnvironmentDir, pipBinaryLocation, "show", depNames);
List<String> allPipShowLines = Arrays.stream(pipShowOutput.split("---")).collect(Collectors.toList());
List<String> allPipShowLines = splitPipShowLines(pipShowOutput);
Map<StringInsensitive,String> CachedTree = new HashMap<>();
List<String> linesOfRequirements;
try {
Expand Down Expand Up @@ -312,4 +312,30 @@ private static int getFirstSign(int rightTriangleBracket, int leftTriangleBrack
equalsSign = equalsSign == -1 ? 999 : equalsSign;
return equalsSign < leftTriangleBracket && equalsSign < rightTriangleBracket ? equalsSign : (leftTriangleBracket < equalsSign && leftTriangleBracket < rightTriangleBracket ? leftTriangleBracket : rightTriangleBracket);
}

static List<String> splitPipShowLines(String pipShowOutput) {
String separator = "---" + System.lineSeparator();

String[] lines = pipShowOutput.split("((?<=\\R))");
List<String> results = new LinkedList<>();

for (int i = 0; i < lines.length; i++) {
StringBuilder sb = new StringBuilder();
for (int j = i; ; j++, i++) {
if (j == lines.length) {
results.add(sb.toString());
break;
}

String line = lines[j];
if (separator.equals(line)) {
results.add(sb.toString());
break;
} else {
sb.append(line);
}
}
}
return results;
}
}
Loading

0 comments on commit ee60826

Please sign in to comment.