Skip to content

Commit 0b9fa5b

Browse files
committed
feat(python): Add a consistency check to python-inspector runs
For `PoetryFunTest`, this shows that there are several inconsistencies that need to be investigated. Relates to #7660 and #10638. Signed-off-by: Sebastian Schuberth <sebastian@doubleopen.org>
1 parent edd1b84 commit 0b9fa5b

1 file changed

Lines changed: 21 additions & 0 deletions

File tree

plugins/package-managers/python/src/main/kotlin/utils/PythonInspector.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import kotlinx.serialization.json.Json
2727
import kotlinx.serialization.json.JsonNamingStrategy
2828
import kotlinx.serialization.json.decodeFromStream
2929

30+
import org.apache.logging.log4j.kotlin.logger
31+
3032
import org.ossreviewtoolkit.utils.common.CommandLineTool
3133
import org.ossreviewtoolkit.utils.common.safeDeleteRecursively
3234
import org.ossreviewtoolkit.utils.ort.createOrtTempFile
@@ -105,6 +107,25 @@ internal object PythonInspector : CommandLineTool {
105107
).requireSuccess()
106108
val binaryResult = outputFile.inputStream().use { json.decodeFromStream<Result>(it) }
107109

110+
// Do a consistency check on the binary packages.
111+
val packagePurls = mutableSetOf<String>()
112+
binaryResult.projects.forEach { project ->
113+
project.packageData.forEach { data ->
114+
data.dependencies.mapTo(packagePurls) { it.purl }
115+
}
116+
}
117+
118+
if (packagePurls.size != binaryResult.packages.size) {
119+
logger.warn {
120+
"The number of unique dependencies (${packagePurls.size}) does not match the number of packages " +
121+
"(${binaryResult.packages.size}), which might indicate a bug in python-inspector."
122+
}
123+
124+
val resultsPurls = binaryResult.packages.mapTo(mutableSetOf()) { it.purl }
125+
logger.warn { "Packages that are not contained as dependencies: ${packagePurls - resultsPurls}" }
126+
logger.warn { "Dependencies that are not contained as packages: ${resultsPurls - packagePurls}" }
127+
}
128+
108129
// TODO: Avoid this terrible hack to run once more with `--prefer-source` to work around
109130
// https://github.com/aboutcode-org/python-inspector/issues/229.
110131
run(

0 commit comments

Comments
 (0)