Skip to content

Commit

Permalink
fix: results of pip show are not properly parsed (#70)
Browse files Browse the repository at this point in the history
## Description

Splitting `pip show` results with `---` could generate incorrect results
when a package contains license information.
An example of such package can be generated by executing `pip3 show
scipy`.

Code in this PR reads the results of `pip show` line by line, and groups
information by packages.

Jira: https://issues.redhat.com/browse/TC-644

## Checklist

- [x] I have followed this repository's contributing guidelines.
- [x] I will adhere to the project's code of conduct.

## Additional information

> Anything else?
  • Loading branch information
xieshenzh authored Oct 23, 2023
1 parent f060dd7 commit 1a8315e
Show file tree
Hide file tree
Showing 2 changed files with 1,976 additions and 1 deletion.
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,8 @@ 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) {
return Arrays.stream(pipShowOutput.split(System.lineSeparator() + "---" + System.lineSeparator())).collect(Collectors.toList());
}
}
Loading

0 comments on commit 1a8315e

Please sign in to comment.